XSL msxsl:node-set 问题 [英] XSL msxsl:node-set problem
问题描述
请大家帮帮我.我只是想声明一个简单的结果树片段并对其进行迭代.
Please help me out guys. I'm just trying to declare a simple result tree fragment and iterate over it.
...
<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>
...
我完全误解了这是如何工作的吗?
Am I completely mistaken about how this works?
我正在使用 .NET XslCompiledTransform 并具有正确的 msxsl 命名空间声明 - xmlns:msxsl="urn:schemas-microsoft-com:xslt"
I'm using .NET XslCompiledTransform and have the correct msxsl namespace declarations - xmlns:msxsl="urn:schemas-microsoft-com:xslt"
转换执行得很好 - 问题是没有输出任何内容
The transformating executes fine - the problem is that nothing is output
推荐答案
我怀疑您在样式表中声明了一个默认命名空间.这将有效地将
My suspicion is that you have a default namespace declared in your stylesheet. That would effectively place the <item-list> and <item> elements into a namespace. To select namespace-qualified elements using XPath 1.0, you must always use a prefix in the expression.
因此,如果您的样式表顶部有这样的内容:
So if you have something like this at the top of your stylesheet:
<xsl:stylesheet xmlns="http://example.com"...>
然后你还需要添加:
<xsl:stylesheet xmlns="http://example.com" xmlns:x="http://example.com"...>
然后在 XPath 表达式中使用x"前缀:
And then use the "x" prefix in your XPath expression:
<xsl:for-each select="msxsl:node-set($rtf)/x:item-list/x:item">
<xsl:value-of select="@id"/>
</xsl:for-each>
让我知道这是否奏效.我只是在这里猜测.
Let me know if that did the trick. I'm only speculating here.
这篇关于XSL msxsl:node-set 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!