下面是我的XML的结构
<FileRoot>
<UserSet1>
<User>
<FirstName></FirstName>
<LastName></LastName>
</User>
<User>
<FirstName></FirstName>
<LastName></LastName>
</User>
...
</UserSet1>
<InactiveUsers>
<User>
<FirstName></FirstName>
<LastName></LastName>
</User>
<User>
<FirstName></FirstName>
<LastName></LastName>
</User>
...
</InactiveUsers>
</FileRoot>
在我的XSL模板中
<xsl:template match="/*/*">
<File>
<xsl attribute name="Name">
<xsl:value-of select="local-name(/*/*)"/>
</xsl:attribute>
</File>
</xsl>
转换后,对于UserSet1和InactiveUsers,都给了我"UserSet1“。对于UserSet1,预期结果应该是"UserSet1“,对于InactiveUsers,预期结果应该是"InactiveUsers”。如何正确检索该值?
谢谢
发布于 2010-05-14 05:59:56
/*/*
是绝对路径,因此local-name(/*/*)
将始终返回整个文档中与该绝对路径匹配的第一个节点的本地名称。看起来您想要当前节点的本地名称。在这种情况下,请改用local-name()
。如果未指定参数,则使用当前上下文节点。
此外,还可以使用属性值模板而不是xsl:attribute
,如下所示:
<xsl:template match="/*/*">
<File Name="{local-name()}"/>
</xsl>
https://stackoverflow.com/questions/2830537
复制相似问题