XSLT extension (for PHP 5, use XSL)
http://www.php.net/manual/en/intro.xslt.phpNOTE:
This extension uses Sablotron and expat, which can both be found at http://www.gingerall.org/sablotron.html. Binaries are provided as well as source.
You must run configure with the --enable-xslt --with-xslt-sablot options.
<?php
$xml = <<<EOT
<?xml version="1.0"?>
<hello-world>
<greeter>An XSLT Programmer</greeter>
<greeting>Hello, World!</greeting>
</hello-world>
EOT;
$xsl = <<<EOT
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/hello-world">
<HTML>
<HEAD>
<TITLE></TITLE>
</HEAD>
<BODY>
<H1>
<xsl:value-of select="greeting"/>
</H1>
<xsl:apply-templates select="greeter"/>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="greeter">
<DIV>from <I><xsl:value-of select="."/></I></DIV>
</xsl:template>
</xsl:stylesheet>
EOT;
$arguments = array(
'/_xml' => $xml,
'/_xsl' => $xsl
);
// Allocate a new XSLT processor
$xh = xslt_create();
// Process the document
$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
if ($result) {
echo "SUCCESS, sample.xml was transformed by sample.xsl into the \$result";
echo " variable, the \$result variable has the following contents\n<br />\n";
//echo "<pre>\n";
echo $result;
//echo "</pre>\n";
} else {
echo "Sorry, sample.xml could not be transformed by sample.xsl into";
echo " the \$result variable the reason is that " . xslt_error($xh);
echo " and the error code is " . xslt_errno($xh);
}
xslt_free($xh);
?>