2009-12-07 75 views
5

请帮帮我吧。我只是试图声明一个简单的结果树片段并对其进行迭代。XSL msxsl:节点集问题


...

<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 = “瓮:架构 - 微软COM:XSLT”

的transformating执行罚款 - 问题是什么都没有输出

+0

我不认为多数民众赞成在足够的代码,并关闭自身实际输出什么... – Murph 2009-12-07 15:04:38

+0

我米并不确定你的意思,但这是整个xslt文件的一个片段。一切高于和低于输出就好了。它只是rtf和节点集,它们不像预期的那样运行。 – Maleks 2009-12-07 17:06:04

回答

8

我怀疑是你在你的样式表声明的默认命名空间。这将有效地将< item-list>和< item>元素放置到名称空间中。要使用XPath 1.0选择符合命名空间限定的元素,您必须始终在表达式中使用前缀。

所以,如果你在你的样式表的顶部有这样的事情:

<xsl:stylesheet xmlns="http://example.com"...> 

然后,你还需要补充一点:

<xsl:stylesheet xmlns="http://example.com" xmlns:x="http://example.com"...> 

然后使用“X”字头在您的XPath表达式中:

<xsl:for-each select="msxsl:node-set($rtf)/x:item-list/x:item"> 
    <xsl:value-of select="@id"/> 
</xsl:for-each> 

让我知道这是否有窍门。我只是在这里猜测。

+0

天才。作品一种享受。 – Maleks 2009-12-08 13:22:43

+0

你的猜测是对的! – Safor 2014-05-21 13:56:40

1

这对我来说很合适。

您是否正确地为扩展函数声明了msxsl名称空间?事情是这样的:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"> 

我假设你正在使用Microsoft XSLT处理器这里

+0

是的,使用MS技术并注册了正确的名称空间。 – Maleks 2009-12-07 13:25:45

4

不像MSXSL,XslCompiledTransform提供node-set()功能它是supposed to be - 在EXSLT公共的命名空间:

<xsl:stylesheet xmlns:exslt="http://exslt.org/common"> 
    ... 
    <xsl:for-each select="exslt:node-set($rtf)/item-list/item"> 
    ... 
</xsl:stylesheet> 
+0

谢谢你的抬头。 – Maleks 2009-12-08 13:23:24

+0

@Pavel Minaev非常感谢!我使用xslt和python,在我的情况下,这是一个很好的解决方案。 – daikini 2012-01-03 03:16:11