2017 © Pedro Peláez
 

library stex

Simple Template Xslt

image

racztiborzoltan/stex

Simple Template Xslt

  • Monday, July 23, 2018
  • by racztiborzoltan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

stex - Simple Template Extended Xslt

Build Status, (*1)

  • extended from PHP built in \XSLTProcessor class.
    • support all \XSLTProcessor features
  • PSR-11 container support
  • some new small syntax

PSR-11 Container support


this:container(...)

this:container('CONTAINER_SCALAR_ITEM_NAME')

this:container('CONTAINER_FUNCTION_ITEM_NAME', 'PARAMETER_1', 'PARAMETER_2', '...')

this:container('CONTAINER_OBJECT_ITEM_NAME', 'METHOD_NAME', 'FIRST_PARAMETER', 'SECOND_PARAMETER', '...')

Usage example:, (*2)

<xsl:value-of select="this:container('scalar_item_name')/>
<xsl:value-of select="this:container('function_item_name', 'foobar', 123)/>
<xsl:value-of select="this:container('object_item_name', 'method_name', 'arg_1', 'arg2')/>

This example code works only with \Stex\StexXsltProcessor class!, (*3)

$xml = <<<EOB
<allusers>
 <user>
  <uid>bob</uid>
 </user>
 <user>
  <uid>joe</uid>
 </user>
</allusers>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:php="http://php.net/xsl">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
 <xsl:template match="allusers">
  <html><body>
    <h2>Users</h2>
    <table border="1" cellspacing="0" cellpadding="5">
      <tr>
        <th>
            Name <br />(php:function)
        </th>
        <th>
            foobar text <br />(this:container)
        </th>
        <th>
            formatted datetime <br />(this:container)
        </th>
      </tr>
    <xsl:for-each select="user">
      <tr>
        <td>
            <xsl:value-of
                select="php:function('ucfirst',string(uid))"/>
        </td>
        <td>
            <xsl:value-of
                select="this:container('foo')"/>
        </td>
        <td>
            <xsl:value-of
                select="this:container('datetime', 'format', 'Y-m-d')"/>
        </td>
      </tr>
    </xsl:for-each>
    </table>
  </body></html>
 </xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = new \DOMDocument();
$xmldoc->loadXML($xml);
$xsldoc = new \DOMDocument();
$xsldoc->loadXML($xsl);

// define container and container items
$container = new Container();
$container->add('foo', 'bar');
$container->add('datetime', function(){
    return new \DateTime();
});

$proc = new StexXsltProcessor();
$proc->setContainer($container);
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);

CSS Select Example

$xml = <<<EOB
<!DOCTYPE html>
<html lang="en">
    <head><title>stex css select demo</title></head>
    <body>
        <section class="first">
            <header>
                <h1 class="title">First section title</h1>
            </header>
            <article>Lorem ipsum...</article>
        </section>
        <section class="second">
            <header>
                <h1 class="title">Second section title</h1>
            </header>
            <article>Dolor it...</article>
        </section>
    </body>
</html>
EOB;
$xsl = <<<EOB
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8" indent="yes"/>
 <xsl:template match="/">

  <xsl:value-of select="@css['section.first .title']"></xsl:value-of>
  <xsl:text>&#xa;</xsl:text>

  <xsl:value-of select="@css['section.second .title']"></xsl:value-of>
  <xsl:text>&#xa;</xsl:text>

  <xsl:for-each select="@css['section article']">
      <xsl:value-of select="."></xsl:value-of>
      <xsl:text>&#xa;</xsl:text>
  </xsl:for-each>

 </xsl:template>
</xsl:stylesheet>
EOB;
$xmldoc = new \DOMDocument();
$xmldoc->loadXML($xml);
$xsldoc = new \DOMDocument();
$xsldoc->loadXML($xsl);

$proc = new StexXsltProcessor();
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
echo $proc->transformToXML($xmldoc);

other examples

in examples directory!, (*4)


http://racztiborzoltan.github.io, (*5)

The Versions

23/07 2018

dev-master

9999999-dev

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

23/07 2018

dev-dev

dev-dev

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

23/07 2018

1.0.4

1.0.4.0

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

21/07 2018

1.0.3

1.0.3.0

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

21/07 2018

dev-dev-2.x

dev-dev-2.x

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

21/07 2018

1.0.2

1.0.2.0

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

21/07 2018

1.0.1

1.0.1.0

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán

18/07 2018

1.0.0

1.0.0.0

Simple Template Xslt

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

by Rácz Tibor Zoltán