[英]How to get next node to be iterated in an XSLT for-each loop?
If I have a for each loop such as: 如果我有每个循环,例如:
<xsl:for-each select="$pChildren">
<xsl:variable name="vNext" select="???" />
</xsl:for-each>
I am trying to assign the next node to be iterated in the for-each loop to vNext
, if any. 我正在尝试将for-each循环中要迭代的下一个节点分配给vNext
(如果有)。
I tried $pChildren[position()+1]
but did not work. 我尝试了$pChildren[position()+1]
但是没有用。
I would prefer to answer this while seeing the entire context, but I believe: 我希望在看到整个上下文时回答此问题,但我相信:
<xsl:for-each select="$pChildren">
<xsl:variable name="i" select="position()" />
<xsl:variable name="vNext" select="$pChildren[$i + 1]" />
</xsl:for-each>
should work for you. 应该为您工作。
If you want to reference the next item in a sequence, you probably shouldn't be using a xsl:for-each statement in the first place. 如果要引用序列中的下一项,则可能首先不应使用xsl:for-each语句。 Reverse the order of the nodes and use xsl:iterate (unless you are making major use of multi-threading). 反转节点的顺序,并使用xsl:iterate(除非您主要使用多线程)。
A more natural way to do this is: 一种更自然的方法是:
<xsl:iterate select="reverse($pchildren)">
<xsl:param name="last" select="()"/>
Do Stuff Here using $last to reference the item that comes next in $pchildren.
<xsl:next-iteration>
<xsl:with-param name="last" select="."/>
</xsl:next-iteration>
</xsl:iterate/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.