Exemplu 3. Making XML into HTML
The following PHP code uses the XML and XSL extensions to
transform XML into presentable HTML.
<?php /* Load the two XML sources */ $xml = new DomDocument; // from /ext/dom $xml->load('example.xml');
$xsl = new DomDocument; $xsl->load('example.xsl');
/* Configure the transformer */ $proc = new xsltprocessor; $proc->importStyleSheet($xsl); // attach the xsl rules echo $proc->transformToXML($xml); // actual transformation ?>
|
This should produce an HTML fragment similar to the following:
Hey! Welcome to my sweet CD collection!
<h1>PHP Rock</h1>
<h2>by Joe Coder</h2>
<h3> - 2003</h3>
<h1>Squashing Typos on a Winter's Eve</h1>
<h2> by kennyt</h2>
<h3> - 2004</h3> |