Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 9th, 2009, 01:26 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old March 9th, 2009, 01:40 AM
Friend of Wrox
Points: 533, Level: 8
Points: 533, Level: 8 Points: 533, Level: 8 Points: 533, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

recursion?
Reply With Quote
  #3 (permalink)  
Old March 9th, 2009, 05:21 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
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)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop a select but with a delay between each try chubnut SQL Server 2005 1 June 11th, 2008 06:26 AM
loop through tables inside .mdb file using VB.NET remya1000 General .NET 3 September 24th, 2007 12:45 PM
Pass variables from array inside a loop dustygn PHP How-To 2 May 3rd, 2006 05:35 PM
Loop issue - with n number of same nodes.. ramesh.kumarm XSLT 3 March 8th, 2006 08:19 AM
Unique Control IDs inside a loop using a varible Joshua Sebastian Classic ASP Basics 2 February 3rd, 2005 10:44 AM



All times are GMT -4. The time now is 08:44 AM.


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