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

TIP

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/.





PHP Phrasebook
PHP Phrasebook
ISBN: 0672328178
EAN: 2147483647
Year: 2005
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net