Skip to content

Instantly share code, notes, and snippets.

@bzerangue
Created March 22, 2012 21:42
Show Gist options
  • Save bzerangue/2164783 to your computer and use it in GitHub Desktop.
Save bzerangue/2164783 to your computer and use it in GitHub Desktop.
PHP: XSLT Transformation
<?php
// You instantiating the XSLTProcessor - libXSLT
$xmlProc = new XsltProcessor();
// Your XSLT Stylesheet for transforming XML
$xslt = new DomDocument();
$xslt -> load("example.xsl");
// This prepares the XSLT for transform
$xmlProc -> importStylesheet($xslt);
// This is your source XML document
$xml = new DomDocument();
$xml -> load("http://domain.com/example.xml");
// Run Tranform and output XML/HTML
if ($output = $xmlProc -> transformToXML($xml))
{
echo $output;
}
// If the transform fails, then it will output this statement below
else
{
echo "<p>This feed is not available.</p>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment