Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2009, 01:26 AM
Friend of Wrox
 
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.
 
Old March 9th, 2009, 01:40 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default

recursion?
 
Old March 9th, 2009, 05:21 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
The Following User Says Thank You to mhkay For This Useful Post:
JohnBampton (March 9th, 2009)





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





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