xml 加载样式表时出错:解析 XSLT 样式表失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7806926/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error loading stylesheet: Parsing an XSLT stylesheet failed
提问by Jayanga Kaushalya
This is my xml file:
这是我的 xml 文件:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="hello.xsl"?>
<message>
<greeting>Hello World!</greeting>
</message>
And this is my xsl file:
这是我的 xsl 文件:
<?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!
当我在 firefox 中运行 xml 文件时,它给出“加载样式表时出错:解析 XSLT 样式表失败”。错误。我是 xml 的新手,请谁能告诉我错误是什么。你能告诉我找到错误的方法吗?谢谢!
采纳答案by Dimitre Novatchev
You have specified a wrong namespace for XSL:
您为 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.
请记住,XML 区分大小写。
回答by Kirill Polishchuk
Change namespace declaration to
将命名空间声明更改为
http://www.w3.org/1999/XSL/Transform
http://www.w3.org/1999/ XSL/转换
回答by darryn.ten
Upping the xsl stylesheet version number from 1.0 to 1.1 worked for me.
将 xsl 样式表版本号从 1.0 提高到 1.1 对我有用。
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/xsl/Transform">
回答by lawrence
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.
解决方案是使用浏览器(在我的情况下为 firefox)打开 xsl 文件,可能会发生错误并修复错误。
In my cases, missing an / slashes in the body tag.
在我的情况下,body 标签中缺少 / 斜线。

