gpt4 book ai didi

xml - 带有根元素中属性的 xml 的 xsl 不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 02:03:10 25 4
gpt4 key购买 nike

我使用生成 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”标签中,输出是一个没有行的表格,但如果我删除属性,它工作正常。

最佳答案

将 namespace 声明添加到 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"/>

关于xml - 带有根元素中属性的 xml 的 xsl 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8166231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com