PHP code example of genkgo / xsl

1. Go to this page and download the library: Download genkgo/xsl 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/ */

    

genkgo / xsl example snippets



use Genkgo\Xsl\XsltProcessor;
use Genkgo\Xsl\Cache\NullCache;

$xslDoc = new DOMDocument();
$xslDoc->load('Stubs/collection.xsl');

$xmlDoc = new DOMDocument();
$xmlDoc->load('Stubs/collection.xml');

$transpiler = new XsltProcessor(new NullCache());
$transpiler->importStylesheet($xslDoc);
echo $transpiler->transformToXML($xmlDoc);


// use omitted for readability

class MyExtension implements XmlNamespaceInterface {

    const URI = 'https://github.com/genkgo/xsl/tree/master/tests/Stubs/Extension/MyExtension';

    public function register(TransformerCollection $transformers, FunctionCollection $functions) {
        $functions->set(
            self::URI, 
            new class extends AbstractLazyFunctionMap {
                public function newFunctionList(): array
                {
                    return [
                        'hello-world' => ['newStringFunction', MyExtension::class],
                    ];
                }
            }
        );
    }

    public static function helloWorld(Arguments $arguments) {
        return 'Hello World was called and received ' . count($arguments->unpack()) . ' arguments!';
    }

}

$factory = new ProcessorFactory(new NullCache(), [new MyExtension()]);
$processor = $factory->newProcessor();


use Genkgo\Xsl\Cache\ArrayCache;
use Genkgo\Xsl\ProcessorFactory;

$factory = new ProcessorFactory(new ArrayCache());
$processor = $factory->newProcessor();