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 May 11th, 2006, 10:48 AM
Authorized User
 
Join Date: Apr 2006
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default For-Each processing problem

Is there a way of "breaking out" of a for-each loop (some sort of Leave instruction)?

I'm processing a set of nodes and doing a test to only pickup a certain condition, however once this condition has been fulfilled I don't wan't to continue checking in case it the condition is true again.

Code:
                <xsl:for-each select="//BookingFareData/BookingData/SeatSegment">
                  <xsl:if test="FlightNbr = $ASFlightNbr and DepartureDate = $ASDate">
                    <xsl:element name="SeatData">
                      <xsl:element name="SeatNumber">
                        <xsl:value-of select="SeatLocation"/>
                      </xsl:element>
                      <xsl:element name="SeatStatus">
                        <xsl:value-of select="SeatStatusCode"/>
                      </xsl:element>
                    </xsl:element>
                 </xsl:if>
                </xsl:for-each>
As always - thanks in advance

 
Old May 11th, 2006, 11:19 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Perhaps you could narrow down the initial node set?
Code:
<xsl:for-each select="(//BookingFareData/BookingData/SeatSegment[FlightNbr = $ASFlightNbr and DepartureDate = $ASDate])[1]">
--

Joe (Microsoft MVP - XML)
 
Old May 11th, 2006, 11:39 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You have to think of a for-each as processing all the elements in parallel rather than in series: there is no way the processing of one element can affect any of the others. If you need to process them sequentially, the answer is to use recursion: write a recursive template (or in 2.0 a function) that takes the list of elements as a parameter, deals with the first one, and then calls itself to handle the rest.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
query processing maheshshinde ASP.NET 2.0 Basics 0 March 21st, 2007 04:14 AM
DATA PROCESSING EXTENSION PROBLEM rodoxdolfo BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 May 11th, 2006 02:38 PM
PROBLEM IN FORM PROCESSING GOUR CHANDRA PAUL PHP Databases 0 April 22nd, 2006 01:18 PM
pre-processing chenggong Crystal Reports 0 July 21st, 2003 09:34 PM





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