2017 © Pedro Peláez
 

library xsl

XSL 2.0 Transpiler in PHP

image

genkgo/xsl

XSL 2.0 Transpiler in PHP

  • Wednesday, June 13, 2018
  • by frederikbosch
  • Repository
  • 4 Watchers
  • 30 Stars
  • 9,000 Installations
  • PHP
  • 3 Dependents
  • 1 Suggesters
  • 4 Forks
  • 5 Open issues
  • 40 Versions
  • 14 % Grown

The README.md

Genkgo/Xsl

XSL 2.0 Transpiler in PHP., (*1)

Installation

Requires supported PHP version. It is installable and autoloadable via Composer as genkgo/xsl., (*2)

Quality

workflow code check, (*3)

To run the unit tests at the command line, issue ./vendor/bin/phpunit -c phpunit.xml. This library attempts to comply with PSR-1, PSR-2, and PSR-4. If you notice compliance oversights, please send a patch via pull request., (*4)

Getting Started

Replace XSLTProcessor with Genkgo\Xsl\XsltProcessor, change version="1.0" in version="2.0" and you are done!, (*5)

<?php
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);

Create your own extenions

You can also register your own extensions. Just implement the XmlNamespaceInterface and you are ready to use your own element transformations and xpath functions. See the example below and the integration test to understand how it works., (*6)

<?php
// 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();

and then call the function in your style sheet., (*7)

<xsl:stylesheet version="2.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:my="https://github.com/genkgo/xsl/tree/master/tests/Stubs/Extension/MyExtension">

    <xsl:output omit-xml-declaration="yes" />

    <xsl:template match="/">
        <xsl:value-of select="my:hello-world(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)" />
    </xsl:template>

</xsl:stylesheet>

will yield: Hello World was called and received 20 arguments!., (*8)

Caching: transpile once

Depending on the complexity of your stylesheet, the transpiling process could slow down the processing of your document. Therefore, you probably want to cache the result stylesheet. By adding psr/simple-cache to your composer.json, you will add the possibility to enable caching. See the example below, or the integration test to see how it works., (*9)

<?php
use Genkgo\Xsl\Cache\ArrayCache;
use Genkgo\Xsl\ProcessorFactory;

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

Contributing

  • Found a bug? Please try to solve it yourself first and issue a pull request. If you are not able to fix it, at least give a clear description what goes wrong. We will have a look when there is time.
  • Want to see a feature added, issue a pull request and see what happens. You could also file a bug of the missing feature and we can discuss how to implement it.

The Versions

13/06 2018

dev-master

9999999-dev

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • ext-xsl *
  • php >=7.0

 

The Development Requires

13/06 2018

0.6.7

0.6.7.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

05/06 2018

0.6.6

0.6.6.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

08/05 2018

0.6.5

0.6.5.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

08/05 2018

0.6.4

0.6.4.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

08/05 2018

0.6.3

0.6.3.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

28/03 2018

0.6.2

0.6.2.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

20/02 2018

0.6.1

0.6.1.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

20/02 2018

0.6.0

0.6.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

29/01 2018

0.5.21

0.5.21.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

17/11 2017

0.5.20

0.5.20.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

16/08 2017

0.5.19

0.5.19.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

01/08 2017

0.5.18

0.5.18.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

18/07 2017

0.5.17

0.5.17.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=7.0
  • ext-xsl *

 

The Development Requires

28/02 2017

0.5.16

0.5.16.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

14/12 2016

0.5.15

0.5.15.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

14/12 2016

0.5.14

0.5.14.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

09/12 2016

0.5.13

0.5.13.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

18/11 2016

0.5.12

0.5.12.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

28/10 2016

0.5.11

0.5.11.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

09/08 2016

0.5.10

0.5.10.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

04/08 2016

0.5.9

0.5.9.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

14/04 2016

0.5.8

0.5.8.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

06/04 2016

0.5.7

0.5.7.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

16/03 2016

0.5.6

0.5.6.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

08/02 2016

0.5.5

0.5.5.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

06/02 2016

0.5.4

0.5.4.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

20/01 2016

0.5.3

0.5.3.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

12/01 2016

0.5.2

0.5.2.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

11/01 2016

0.5.1

0.5.1.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

06/01 2016

0.5.0

0.5.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

26/10 2015

0.4.0

0.4.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

20/10 2015

0.3.1

0.3.1.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

20/10 2015

0.3.0

0.3.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

19/10 2015

0.2.4

0.2.4.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

19/10 2015

0.2.3

0.2.3.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

19/10 2015

0.2.2

0.2.2.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

19/10 2015

0.2.1

0.2.1.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

19/10 2015

0.2.0

0.2.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires

18/10 2015

0.1.0

0.1.0.0

XSL 2.0 Transpiler in PHP

  Sources   Download

The Requires

  • php >=5.6
  • ext-xsl *

 

The Development Requires