Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an XML and XSL file to be loaded onto a webpage as HTML. for some reason this is not working .. the data isn't being displayed in a table on to a web browser.

Here is my code below, is there anything that i am missing? please help?

XML file
XML
<?xml version="1.0"?>
<?xml-stylesheet href="skymovies.xsl" type="text/xsl"?>
<collection>
   <film>
      <title>Happy Gilmore</title>
      <year>1991</year>
      <genre>Comedy</genre>
    </film>
    <film>
      <title>Rango</title>
      <year>1991</year>
      <genre>Comedy</genre>
     </film>
     <film>
     <title>Happy Gilmore</title>
      <year>1991</year>
      <genre>Comedy</genre>
      </film>

   </movie>
</collection>


XSLT File

XML
<?xml version="1.0" encoding="IS0-8859-1"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/collection">
<html>
<body>
<table border="1">
     <tr>
     <th>Title</th>
     <th>Year</th>
     <th>Genre</th>
     </tr>

    <xsl:for-each select="film">
       <xsl:value-of select="title" /></td>
       <xsl:value-of select="year" /></td>
       <xsl:value-of select="genre" /></td>
    </xsl:for-each>
    </table>


</body>
</html>


</xsl:template>
</xsl:stylesheet>




Is there anythig i'm doing wrong? please help?
Posted
Updated 12-Jan-14 6:39am
v2

1 solution

There is something wrong with your encoding, you're using a zero instead of an 'O'
Use the following:
XML
<?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="/collection">
<html>
<body>
<table border="1" >
     <tr>
     <th>Title</th>
     <th>Year</th>
     <th>Genre</th>
     </tr>

    <xsl:for-each select="film">
    <tr>
       <td><xsl:value-of select="title" /></td>
       <td><xsl:value-of select="year" /></td>
       <td><xsl:value-of select="genre" /></td>
    </tr>
    </xsl:for-each>
    </table>
</body>
</html>
</xsl:template>


</xsl:stylesheet>


Also, you have an orphaned </movie> tag
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900