我想在我的网站上的表格中显示一些打印机配件。产品通过xml文件提供。我从服务器下载的文件。它应该用作另一个网站的Feed。但是我无法让它在离线状态下工作。
document.xml文件是这样的:
<?xml version="1.0" encoding="utf-8"?>
<root>
<Produs>
<ID><![CDATA[10281]]></ID>
<Grupa><![CDATA[Accesorii Laser]]></Grupa>
<PN><![CDATA[SKY-HP CP1215-PCR]]></PN>
<Producator><![CDATA[HP]]></Producator>
<OEM><![CDATA[CB540A / CB541A / CB542A / CB543A
CE320A / CE321A / CE322A / CE323A]]></OEM>
<Imprimante><![CDATA[HP LaserJet Pro CM1410 / CM1415 / CM1415fn / CM1415fnw / CP1525 / CP1525n / CP1525nw;
HP LaserJet CM1312 / CP1215 / CP1217 / CP1510 / CP1514 / CP1515 / CP1515n / CP1518 / CP1518n]]></Imprimante>
<NumarPagini><![CDATA[0]]></NumarPagini>
<Culoare><![CDATA[Black]]></Culoare>
<Greutate><![CDATA[0]]></Greutate>
<Cantitate><![CDATA[1]]></Cantitate>
<Stoc><![CDATA[Stoc]]></Stoc>
<Pret><![CDATA[4.50]]></Pret>
<Valuta><![CDATA[USD]]></Valuta>
</Produs>
...
</Produs>
</root>
我已经使用以下内容创建了form.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Accessorii imprimante</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ID</th>
<th>Grupa</th>
<th>PN</th>
<th>Producator</th>
<th>OEM</th>
<th>Imprimante</th>
<th>NumarPagini</th>
<th>Culoare</th>
<th>Greutate</th>
<th>Cantitate</th>
<th>Stoc</th>
<th>Pret</th>
<th>Valuta</th>
</tr>
<xsl:for-each select="root/produs">
<tr>
<td><xsl:value-of select="ID"/></td>
<td><xsl:value-of select="Grupa"/></td>
<td><xsl:value-of select="PN"/></td>
<td><xsl:value-of select="Producator"/></td>
<td><xsl:value-of select="OEM"/></td>
<td><xsl:value-of select="Imprimante"/></td>
<td><xsl:value-of select="NumarPagini"/></td>
<td><xsl:value-of select="Culoare"/></td>
<td><xsl:value-of select="Greutate"/></td>
<td><xsl:value-of select="Cantitate"/></td>
<td><xsl:value-of select="Stoc"/></td>
<td><xsl:value-of select="Pret"/></td>
<td><xsl:value-of select="Valuta"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
为了显示它,我发现了这个PHP代码:
<?php
$xslDoc = new DOMDocument();
$xslDoc->load("form.xsl");
$xmlDoc = new DOMDocument();
$xmlDoc->load("document.xml");
$proc = new XSLTProcessor();
$proc->importStylesheet($xslDoc);
echo $proc->transformToXML($xmlDoc);
?>
结果是浏览器只显示表头,仅此而已。 以下是生成的结果:
<html><body>
<h2>Accessorii imprimante</h2>
<table border="1"><tr bgcolor="#9acd32">
<th>ID</th>
<th>Grupa</th>
<th>PN</th>
<th>Producator</th>
<th>OEM</th>
<th>Imprimante</th>
<th>NumarPagini</th>
<th>Culoare</th>
<th>Greutate</th>
<th>Cantitate</th>
<th>Stoc</th>
<th>Pret</th>
<th>Valuta</th>
</tr></table>
</body></html>
答案 0 :(得分:1)
XML区分大小写。变化:
<xsl:for-each select="root/produs">
为:
<xsl:for-each select="root/Produs">