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.
I tried $pChildren[position()+1]
but did not work.
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. Reverse the order of the nodes and use xsl:iterate (unless you are making major use of multi-threading).
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/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.