Picasso2011
Picasso2011

Reputation: 3

xsl transform not working

I wanted to display some printer accessories in a table on my website. The products are provided via xml file. The file I have downloaded from a server. It should be used as feed in another website. But I am unable to make it work even offline.

The document.xml file is something like this:

<?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>

I have created the form.xsl with these content:

<?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>

And to display it I found this php code:

<?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);

?>

The result is the browser is displaying just the table header and nothing more. Here is the result generated:

<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>

Upvotes: 0

Views: 57

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116993

XML is case-sensitive. Change:

<xsl:for-each select="root/produs">

to:

<xsl:for-each select="root/Produs">

Upvotes: 1

Related Questions