Jump to content

error when applys xsl to xml


hommer

Recommended Posts

It’s great tutorial for a beginner like me.I followed through the screens, now I want to test it on my own. I created (or copied to be exact) both the xsl and xml files on notepad. But I got error when I browsed to the xml either by http://localhost/cdcatalog.xml or double clicked on: C:\Inetpub\wwwroot\cdcatalog.xml.The error message points to my second line of the xml file, which is an exact copy from the tutorial.What did I do wrong? Below are my xsl and xml. Thanks!cdcatalog.xsl <xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><h2>My CD Collection</h2><table><tr><th>first header</th><th>second header</th></tr><xsl:for-each select="catalog/cd"> <tr><td><xsl:value-of Select="catalog/cd/Title"/></td> <td><xsl:value-of Select="catalog/cd/Artist"/></td> </tr></xsl:for-each></table></body></html></xsl:template></xsl:stylesheet>cdcatalog.xml<?xml version="1.0" encoding="ISO-8859-1" ?> <?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>- <catalog>- <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd>- <cd> <title>Hide your heart</title> <artist>Bonnie Tyler</artist> <country>UK</country> <company>CBS Records</company> <price>9.90</price> <year>1988</year> </cd>- <cd> <title>Greatest Hits</title> <artist>Dolly Parton</artist> <country>USA</country> <company>RCA</company> <price>9.90</price> <year>1982</year> </cd></catalog>

Link to comment
Share on other sites

You have a couple of things wrong here.1) XML, XSLT is case sensitive.2) You've extended your paths.3) You'll need to remove the dashes in your XML file.

<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><h2>My CD Collection</h2><table><tr><th>first header</th><th>second header</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></html></xsl:template></xsl:stylesheet>

And you'll want to remove the dashes from your xml file.Let us know if you have more questions.

Link to comment
Share on other sites

Thank you for the reply. Now it is working!

You have a couple of things wrong here.1) XML, XSLT is case sensitive.2) You've extended your paths.3) You'll need to remove the dashes in your XML file.
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><h2>My CD Collection</h2><table><tr><th>first header</th><th>second header</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></html></xsl:template></xsl:stylesheet>

And you'll want to remove the dashes from your xml file.Let us know if you have more questions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...