Example 3. Making XML into HTML
The following PHP code uses the XML and XSL extensions to
transform XML into presentable HTML.
|
<?php
$xml = new DomDocument; $xml->load('example.xml');
$xsl = new DomDocument;
$xsl->load('example.xsl');
$proc = new xsltprocessor;
$proc->importStyleSheet($xsl); echo $proc->transformToXML($xml); ?>
|
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> |