Test.xml:<?xml version="1.0" encoding="ISO-8859-1"?><catalog><cd><title>Empire Burlesque</title><artist>Bob Dylan</artist><country>USA</country><company>Columbia</company><price>10.90</price><year>1985</year></cd></catalog>
Test.xsl:<?xml version="1.0" encoding="ISO-8859-1"?><xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match= "/" >
<body>
<table border= "1" >
<tr bgcolor= "#9acd32" >
<th align= "left" >Title</th>
<th align= "left" >Artist</th>
</tr>
<xsl:for-each select= "CATALOG/CD" >
<tr>
<td><xsl:value-of select= "title"/></td>
<td><xsl:value-of select= "Artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>
3. test.php:
<?php
$xslDoc = new DOMDocument ();
$xslDoc->load ("test.xsl");
$xmlDoc = new DOMDocument ();
$xmlDoc->load ("Test.xml");
$proc = new Xsltprocessor ();
$proc->importstylesheet ($XSLDOC);
echo $proc->transformtoxml ($XMLDOC);
4. 输出:
<body>
<table border= "1" >
<tr bgcolor= "#9acd32" >
<th align= "left" >Title</th>
<th align= "left" >Artist</th></tr>
<tr>
<td>empire burlesque</td>
<td>bob dylan</td></tr>
</table>
</body>
PHP converts an XML file to HTML