11
votes

This is my xml file:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<message>
    <greeting>Hello World!</greeting>
</message>

And this is my xsl file:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/Transform">
<xsl:template match="/">
<html>
<body>
<h1><xsl:value-of select="message/greeting"/></h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

When I run the xml file in firefox it gives "Error loading stylesheet: Parsing an XSLT stylesheet failed." error. I am new to xml please can anyone tell me what is the error. And can you tell me a way to find the error. Thanks!

4
Why in blazes was this downvoted twice? It's an honest question and an easy mistake to make. URLs and case-sensitivity are common sources of confusion with regard to namespaces.G_H
@G_H: Absolutely agree -- I just upvoted this question to counter the downvotes. Do the same and we bring it back to 0.Dimitre Novatchev
Done. There might be nearly identical questions, but you would only notice that once you know the actual problem. I sure wouldn't have seen it just by looking at the stylesheet.G_H

4 Answers

10
votes

You have specified a wrong namespace for XSL:

xmlns:xsl="http://www.w3.org/1999/xsl/Transform"

Instead, you must use:

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

Remember that XML is case-sensitive.

6
votes

Change namespace declaration to

http://www.w3.org/1999/XSL/Transform

4
votes

Upping the xsl stylesheet version number from 1.0 to 1.1 worked for me.

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/xsl/Transform">
2
votes

I had a same problem as you. Finally I found out my solution.

The solution is that open the xsl file with your browser(in my case firefox) and the error may occurs and fix the error.

In my cases, missing an / slashes in the body tag.