PHP code example of rakshitbharat / laravel-xslt

1. Go to this page and download the library: Download rakshitbharat/laravel-xslt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rakshitbharat / laravel-xslt example snippets


Krowinski\LaravelXSLT\XSLTServiceProvider::class,

/**
 * 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');
}

use Krowinski\LaravelXSLT\Engines\XSLTEngine;

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




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);
    }
}
bash
php artisan make:listener XSLTDebugBar --event XSLTEngineEvent