View Single Post
  #3 (permalink)  
Old March 9th, 2009, 05:21 AM
mhkay's Avatar
mhkay mhkay is offline
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
JohnBampton (March 9th, 2009)