排序的 exsl:节点集。按位置返回节点
我有一组节点,
<menuList>
<mode name="aasdf"/>
<mode name="vfssdd"/>
<mode name="aswer"/>
<mode name="ddffe"/>
<mode name="ffrthjhj"/>
<mode name="dfdf"/>
<mode name="vbdg"/>
<mode name="wewer"/>
<mode name="mkiiu"/>
<mode name="yhtyh"/>
and so on...
</menuList>
现在以这种方式对其进行排序
<xsl:variable name="rtf">
<xsl:for-each select="//menuList/mode">
<xsl:sort data-type="text" order="ascending" select="@name"/>
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:variable>
现在我需要将排序数组中的任意元素获取到其位置数。我正在使用代码:
<xsl:value-of select="exsl:node-set($rtf)[position() = 3]"/>
并且收到响应错误。我应该怎样做呢?
I have a set of nodes
<menuList>
<mode name="aasdf"/>
<mode name="vfssdd"/>
<mode name="aswer"/>
<mode name="ddffe"/>
<mode name="ffrthjhj"/>
<mode name="dfdf"/>
<mode name="vbdg"/>
<mode name="wewer"/>
<mode name="mkiiu"/>
<mode name="yhtyh"/>
and so on...
</menuList>
I have it sorted now this way
<xsl:variable name="rtf">
<xsl:for-each select="//menuList/mode">
<xsl:sort data-type="text" order="ascending" select="@name"/>
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:variable>
Now I need to get an arbitrary element in the sorted array to the number of its position. I'm using the code:
<xsl:value-of select="exsl:node-set($rtf)[position() = 3]"/>
and I get a response error. How should I be doing it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提供的代码中至少有两个错误:
当更多时如果存在多个相邻文本节点,则将它们合并为一个。结果是 RTF 只有一个(长)单个文本节点,并且没有第三个节点。
2
.
< /strong>这要求包含在
exsl:node-set($rtf)
中的第三个节点,但是exsl:node-set($rtf)
是由exsl:node-set()
扩展函数生成的临时树 - 这只是一个节点。因此,上面的 XPath 表达式根本不选择任何内容。一个正确的解决方案如下:
There are at least two errors in the provided code:
<xsl:value-of select="@name"/>
When more than one adjacent text node exist, they are combined into one. The result is that the RTF has just one (long) single text node, and there isn't a 3rd node.
2
.<xsl:value-of select="exsl:node-set($rtf)[position() = 3]"/>
This asks for the third node contained in
exsl:node-set($rtf)
, howeverexsl:node-set($rtf)
is the document node of the temporary tree produced by theexsl:node-set()
extension function -- this is only one node. Therefore the above XPath expression doesn't select anything at all.One correct solution is the following:
您在变量中使用
。这不会复制节点,而是复制其字符串值(节点的@name
属性值)。这意味着您会生成一个包含连接字符串的变量,但不包含任何结构。尝试:
现在您的变量包含一个结果树片段,该片段由按您首选顺序排列的
节点组成,这意味着 this:可以工作。另请注意,
…/*[position() = 3]
和…/*[3]
是同一件事。You use
<xsl:value-of>
in your variable. This does not copy the node, but its string value (the node's@name
attribute value). This means you produce a variable containing a concatenated string, but nothing with a structure.Try:
Now your variable contains a result tree fragment consisting of
<mode>
nodes in your preferred order, which means that this:would work. Also note that
…/*[position() = 3]
and…/*[3]
are the same thing.