Transforming XML with XSLT
Use PHP’s XSLT extension:
// Load XSL template $xsl = newDOMDocument; $xsl->load('stylesheet.xsl'); // Create new XSLTProcessor $xslt = new XSLTProcessor(); // Load stylesheet $xslt->importStylesheet($xsl); // Load XML input file $xml = new DOMDocument; $xml->load('data.xml'); // Transform to string $results = $xslt->transformToXML($xml); // Transform to a file $results = $xslt->transformToURI($xml, 'results.txt'); // Transform to DOM object $results = $xslt->transformToDoc($xml);
The transformed text is stored in $results.
Filed Under: PHP XML Examples