PHP Classes
elePHPant
Icontem

Laravel XSLT: Render templates in XSLT for Laravel applications

Recommend this page to a friend!
  Info   View files Documentation   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-11-28 (12 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 12 This week: 2All time: 9,775 This week: 193Up
Version License PHP version Categories
laravel-xslt 1.0MIT/X Consortium ...5XML, PHP 5, Libraries, Templates
Description Author

This package can render templates in XSLT for Laravel applications.

It provides service that can render templates defined in XSLT format, so Laravel views can generate output using this service using given template parameter values.

The debugBar component can be used to output debug information by the means of an event handler that can integrate with this XSLT template rendering engine.

Innovation Award
PHP Programming Innovation award nominee
November 2019
Nominee
Vote
XSLT is a language that can define transformations to be done on XML documents that applications may need to be processed.

It can also be used as a template language that can retrieve parts of a source document and generate an output document.

This package allows using XSLT templates to generate the output of views of a Laravel based application.

It can also be extended using event handlers to transform further the view output with additional components like a debug bar.

Manuel Lemos
  Performance   Level  
Name: Kacper Rowinski <contact>
Classes: 13 packages by
Country: Poland Poland
Age: 35
All time rank: 100628 in Poland Poland
Week rank: 95 Up4 in Poland Poland Up
Innovation award
Innovation award
Nominee: 7x

 

Details

laravel-xslt

Latest Stable Version Total Downloads Latest Unstable Version License

XSLT template engine for laravel 5

Instalation

  1. Install using composer in your laravel project
composer require krowinski/laravel-xslt

  1. Add this line to app.php at the end of 'providers' array (in file config/app.php)
Krowinski\LaravelXSLT\XSLTServiceProvider::class,

  1. Create welcome.xsl in resources/views
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exslt="http://exslt.org/common" xmlns:str="http://exslt.org/strings" xmlns:php="http://php.net/xsl" exclude-result-prefixes="exslt str php">

    <xsl:output encoding="UTF-8" method="xml" omit-xml-declaration="yes" indent="yes"
                doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
                doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" cdata-section-elements="script"/>

    <xsl:template match="/">

        <head>
            <title>Laravel</title>

            <link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css"/>

            <style>
                html, body {
                height: 100%;
                }

                body {
                margin: 0;
                padding: 0;
                width: 100%;
                display: table;
                font-weight: 100;
                font-family: 'Lato';
                }

                .container {
                text-align: center;
                display: table-cell;
                vertical-align: middle;
                }

                .content {
                text-align: center;
                display: inline-block;
                }

                .title {
                font-size: 96px;
                }
            </style>

        </head>
        <body>
            <div class="container">
                <div class="content">
                    <div class="title">Laravel 5 XSLT engine template</div>
                </div>
            </div>
        </body>
    </xsl:template>

</xsl:stylesheet>

  1. Add data to xml using simple xml functions
/
 * Show the application welcome screen to the user.
 *
 * @return Response
 */
public function index()
{	
	// adds to main xml /App attributte name template with value  = hello
	\View::addAttribute('name_template ', 'hello');
	// create child template to /App with value hello and add aaa and zzz atribute to template.
	\View::addChild('template', 'hello', false)->addAttribute('aaaa', 'zzz');
	// creates parent example and adds childs foo and bar to it 
	\View::addArrayToXmlByChild(['foo', 'bar'], 'example', false); 
	// add to parent App child bar and zzz
	\View::addArrayToXml(['bar', 'zzz'], false);

	return view('welcome');
}

Add xml to debugBar (https://github.com/barryvdh/laravel-debugbar)

Add to EventServiceProvider.php

use Krowinski\LaravelXSLT\Engines\XSLTEngine;

and to protected $listen array

XSLTEngine::EVENT_NAME => [
    'App\Listeners\XSLTDebugBar'
],
         

create file Listeners\XSLTDebugBar.php

php artisan make:listener XSLTDebugBar --event XSLTEngineEvent

event content

  
<?php


namespace App\Listeners;


use DebugBar\DataCollector\MessagesCollector;
use DebugBar\DebugBar;
use Illuminate\Support\Facades\App;
use Krowinski\LaravelXSLT\Events\XSLTEngineEvent;

/
 * Class XSLTDebugBar
 * @package App\Listeners
 */
class XSLTDebugBar
{
    /
     * @param XSLTEngineEvent $event
     */
    public function handle(XSLTEngineEvent $event)
    {
        $dom = new \DOMDocument;
        $dom->preserveWhiteSpace = false;
        $dom->loadXML($event->getExtendedSimpleXMLElement()->saveXML());
        $dom->formatOutput = true;
        $xmlString = $dom->saveXML();

        / @var DebugBar $debugBar */
        $debugBar = App::make('debugbar');
        if (!$debugBar->hasCollector('XML')) {
            $debugBar->addCollector(new MessagesCollector('XML'));
        }
        / @var MessagesCollector $collector */
        $collector = $debugBar->getCollector('XML');
        $collector->addMessage($xmlString, 'info', false);
    }
}
           
  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files  /  src  
File Role Description
Files folder imageXSLT (2 files, 3 directories)

  Files folder image Files  /  src  /  XSLT  
File Role Description
Files folder imageEngines (2 files)
Files folder imageEvents (1 file)
Files folder imageException (2 files)
  Plain text file XSLTFactory.php Class Class source
  Plain text file XSLTServiceProvider.php Class Class source

  Files folder image Files  /  src  /  XSLT  /  Engines  
File Role Description
  Plain text file ExtendedSimpleXMLElement.php Class Class source
  Plain text file XSLTEngine.php Class Class source

  Files folder image Files  /  src  /  XSLT  /  Events  
File Role Description
  Plain text file XSLTEngineEvent.php Class Class source

  Files folder image Files  /  src  /  XSLT  /  Exception  
File Role Description
  Plain text file IncorrectDataTypeException.php Class Class source
  Plain text file MethodNotFoundException.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:12
This week:2
All time:9,775
This week:193Up