[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: is there a way to break out of the xsl:for-each loop ?


xsl for each break
At 2004-03-23 08:38 -0600, Bill Riegel wrote:
>What to look thru a listOfNodes, and set contents on a variable, foundIt,
>when I found what I am looking for, then break.

XSLT does not work this way ... the semantics for an <xsl:for-each> are 
different than a programmer's "for loop".

><xsl:variable name="foundIt">
>         <xsl:for-each select="$listofNodes">
>                 <xsl:if test="string(current()) = $mySearchItem">
>                         <!-- break out of look if found what I am looking
>for -->
>                         <xsl:break>
>                 </xsl:if>
>         </xsl:for-each>
></xsl:variable>
>
><!-- do something with foundIt -->

XSLT does not work this way either ... variables are bound with a value and 
cannot change within their scope.

You haven't described what you want to do to your information, you have 
only described a non-functional programmer's approach to a coding pattern.

Perhaps you need something like:

   <xsl:for-each select="$listofNodes[.=$mySearchItem]">
     <!--do something with found nodes equal to my search item-->
   </xsl:for-each>

When using XSLT you merely address the nodes that you want to process 
rather than attempting a circuitous design pattern based on traditional 
programming techniques.

I hope this helps.

............................ Ken

--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@C...
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/x/bc



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.