Here's a very simple example on how to use PHP5 to transform a XML file using a XSL file. <?php $xslDoc = new DOMDocument(); $xslDoc->load("collection.xsl"); $xmlDoc = new DOMDocument(); $xmlDoc->load("collection.xml"); $proc = new XSLTProcessor(); $proc->importStylesheet($xslDoc); echo $proc->transformToXML($xmlDoc); ?> For the sake of simplicity there's no error handling on this code. I hope this helps.
This is more convenient, no files nor verbose variables needed: <?php $xslt = new XSLTProcessor(); $xslt->importStylesheet(new SimpleXMLElement($xslt_string)); echo $xslt->transformToXml(new SimpleXMLElement($xml_string)); ?>
Коментарии
Here's a very simple example on how to use PHP5 to transform a XML file using a XSL file.
<?php
$xslDoc = new DOMDocument();
$xslDoc->load("collection.xsl");
$xmlDoc = new DOMDocument();
$xmlDoc->load("collection.xml");
$proc = new XSLTProcessor();
$proc->importStylesheet($xslDoc);
echo $proc->transformToXML($xmlDoc);
?>
For the sake of simplicity there's no error handling on this code. I hope this helps.
This is more convenient, no files nor verbose variables needed:
<?php
$xslt = new XSLTProcessor();
$xslt->importStylesheet(new SimpleXMLElement($xslt_string));
echo $xslt->transformToXml(new SimpleXMLElement($xml_string));
?>