p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Loop twice, then inside loop select nodes?? (http://p2p.wrox.com/showthread.php?t=73178)

JohnBampton March 9th, 2009 01:26 AM

Loop twice, then inside loop select nodes??
 
If I have a for-each loop that I want to loop through 2 times and then select nodes inside that??

When I try to do this I get error ="cannot select nodes here as the context item is atomic"

I understand the error but was wondering if there was a work around?

Regards.

JohnBampton March 9th, 2009 01:40 AM

recursion?

mhkay March 9th, 2009 05:21 AM

xsl:for-each changes the context item. If, within the loop, you want to access the item that was the context item outside the loop, you need to bind a variable before the context item disappears:

Code:

<xsl:variable name="c" select="."/>
<xsl:for-each select="....">
    <xsl:value-of select="$c/x/y/z"/>

This applies regardless whether the inner for-each selects nodes or atomic values, but in the case where it selects atomic values there is the advantage that you get an error message.


All times are GMT -4. The time now is 01:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.