1 Replies - 7002 Views - Last Post: 18 March 2013 - 02:47 PM

#1 bcusick  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-November 12

apply XSLT file to XML file to convert into HTML

Posted 18 March 2013 - 01:36 PM

I am trying to use an .xslt to my .xml so I can display it in HTML. My HTML homepage has a banner, with a navigation bar. One of the links on my navi bar is supposed to href to inventory.xml. My inventory.xml uses the stylesheet inventory.xslt. In my xml file, I have :
<?xsl-stylesheet type = "text/xsl" href= "inventory.xslt"?>


However, when I try to get to the xml page on any browser (chrome, firefox, ie9) it just displays my raw xml file. If anyone could help, I'd really, really like to stop banging my head against this table.

Oh by the way-I am using Visual Studio '10.

This is my stylesheet (inventory.xslt) I do not believe I am missing anything though. I know I am supposed to validate using a schema for my class, but do I need to do that before I can display the page?


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

    <xsl:template match="/">
      <html>
        <HEAD>
          <title>Inventory</title>
        </HEAD>
      <body>
          <h2>Bookstore Inventory</h2>
        <table border="1">
          <tr bgcolor="#9acd32">
            <th>Title</th>
            <th>Author</th>
            <th>Year</th>
            <th>Price</th>
          </tr>
          <xsl:for-each select="bookstore/book">
            <tr>
              <td>
                <xsl:value-of select="title"/>
              </td>
              <td>
                <xsl:value-of select="author"/>
              </td>
              <td>
                <xsl:value-of select="year"/>
              </td>
              <td>
                <xsl:value-of select="price"/>
              </td>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
</xsl:template>

</xsl:stylesheet>





Is This A Good Question/Topic? 0
  • +

Replies To: apply XSLT file to XML file to convert into HTML

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3331
  • View blog
  • Posts: 11,261
  • Joined: 12-December 12

Re: apply XSLT file to XML file to convert into HTML

Posted 18 March 2013 - 02:47 PM

I believe it should be:

<?xml-stylesheet type = "text/xsl" href= "inventory.xslt"?>

Are both files in the same location?

Try with the extension .xsl rather than .xslt.

If it still doesn't work then, yes, you need to validate both documents; if either are malformed then the transformation won't occur.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1