请帮帮我吧伙计们。我只是想声明一个简单的结果树片段并对其进行迭代。
...
<xsl:variable name="rtf">
<item-list>
<item id="1">one</item>
<item id="2">two</item>
<item id="3">three</item>
<item id="4">four</item>
</item-list>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($rtf)/item-list/item">
<xsl:value-of select="@id"/>
</xsl:for-each>
...
我完全误解了这是如何工作的吗?
编辑:
我正在使用 .NET XslCompiledTransform 并具有正确的 msxsl 命名空间声明 - xmlns:msxsl="urn:schemas-microsoft-com:xslt"
转换执行得很好 - 问题是没有输出任何东西
最佳答案
我怀疑您在样式表中声明了一个默认命名空间。这将有效地将
因此,如果您的样式表顶部有这样的内容:<xsl:stylesheet xmlns="http://example.com"...>
然后你还需要添加这个:<xsl:stylesheet xmlns="http://example.com" xmlns:x="http://example.com"...>
然后在 XPath 表达式中使用“x”前缀:<xsl:for-each select="msxsl:node-set($rtf)/x:item-list/x:item">
<xsl:value-of select="@id"/>
</xsl:for-each>
让我知道这是否有效。我只是在这里猜测。
关于xslt - XSL msxsl :node-set problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1859839/