提问人:eniac 提问时间:11/17/2011 最后编辑:Kirill Polishchukeniac 更新时间:11/17/2011 访问量:1812
在根元素中带有 XML 和属性的 XSL 不起作用
xsl with xml with attribute in root element does not work
问:
我使用生成 xml 文件的 sw,我想在 html 文件中显示该文件,所以我开始创建一个 xsl 文件来为我执行此操作。 问题是由于属性的原因,我不知道如何解决错误列表根元素。如果我从 xml 文件中删除属性,则 xsl 工作正常。
我的xml文件是:
<errorList xmlns="http://www.klocwork.com/inForce/report/1.0" version="9.1.0">
<problem>
<problemID>1</problemID>
<file>stdafx.h</file>
</problem>
<problem>
...
</problem>
</errorList>
到目前为止,我的 xsl 是:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Issues</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>ProblemID</th>
<th>File</th>
</tr>
<tr>
<td><xsl:value-of select="errorList/problem/problemID"/></td>
<td><xsl:value-of select="errorList/problem/file"/></td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
问题是,如果属性存在于“errorList”标签中,则输出是一个没有行的表,但是如果我删除属性,它可以正常工作。
答:
3赞
Michael Krelin - hacker
11/17/2011
#1
<xsl:stylesheet version="1.0"
xmlns:k="http://www.klocwork.com/inForce/report/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
,然后将其引用为 .k:errorList
评论
0赞
LarsH
11/17/2011
呃。。。version=“9.1.0”?你来自未来吗?:-)
0赞
Michael Krelin - hacker
11/17/2011
还有 version=“1.0” :)从 OP 的 xml 中复制了太多,谢谢,我会把它编辑掉。
2赞
LarsH
11/18/2011
很遗憾,我本来想问你 XSLT 9.1.0 中有哪些功能。
0赞
Michael Krelin - hacker
11/22/2011
@eniac,是的,只是一开始我用你的命名空间声明复制了它,LarsH 取笑我。
4赞
Kirill Polishchuk
11/17/2011
#2
向 XSLT 添加命名空间声明:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:k="http://www.klocwork.com/inForce/report/1.0">
然后使用它:
<xsl:value-of select="k:errorList/k:problem/k:problemID"/>
评论