I have XML data and am trying to use XSL to format the data. I am following some tutorials. When previewing the XML in Internet Explorer the data is on one line; when previewing with Firefox I get the error message:
Error loading stylesheet: Parsing an XSLT stylesheet failed.
Here the XML:
<?xml version= "1.0"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<countries>
<country>
<countryname>United States</countryname>
</country>
<country>
<countryname>United Kingdom</countryname>
</country>
<country>
<countryname>Deutschland</countryname>
</country>
<country>
<countryname>Osterreich</countryname>
</country>
<country>
<countryname>Espana</countryname>
</country>
<country>
<countryname>France</countryname>
</country>
<country>
<countryname>Italia</countryname>
</country>
<country>
<countryname>China</countryname>
</country>
<country>
<countryname>Hong Kong</countryname>
</country>
<country>
<countryname>Japan</countryname>
</country>
<country>
<countryname>Singapore</countryname>
</country>
<country>
<countryname>Taiwan</countryname>
</country>
<country>
<countryname>Malaysia</countryname>
</country>
</countries>
Here is the XSL:
<?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="/countries">
<html>
<body>
<xsl:for-each select="country"
<xsl:value-of select="countryname"/><br/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylsheet>
Why does the browser not display the XML document as described by the XSL template?
Thank you!
Missing Bracket
<xsl:for-each select="country"must be<xsl:for-each select="country">.Note the closing
>.Extra Space
Also, you may wish to remove the leading spaces on the first line of the document, if they exist:
vs
Typo
</xsl:stylsheet>must be</xsl:stylesheet>After making these changes, the list of countries appear.
Debugging
Consider editing XML and XSL using a text editor that has syntax highlighting and would alert you visually to such errors.