Transforming XML with XSL and PHP 5
$result = $xslt->transformToDoc($xml);
echo $result->saveXML();
|
On PHP 5, XSLT is done by libxslt and can be enabled using php_xsl.dll (in php.ini) on Windows and the switch with-xsl on other platforms. The approach is a bit different: Load both the XML and the XSLT (which is an XML document, as well) into a DOM object, then instantiate an XsltProcessor object. Call importStylesheet() and then transformToDoc().
Using XSLT with PHP 5 (xslt5.php)
<?php
$xml = new DOMDocument();
$xml->load('quotes.xml');
$xsl = new DOMDocument();
$xsl->load('quotes.xsl');
$xslt = new XsltProcessor();
$xslt->importStylesheet($xsl);
$result = $xslt->transformToDoc($xml);
echo $result->saveXML();
?>
Once again, there is a script that makes the two incompatible XSLT implementations compatible with each other. You find it at http://alexandre.alapetite.net/doc-alex/xslt-php4-php5/. |
|