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

Re: <xsl:for-each>

Subject: Re: <xsl:for-each>
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Fri, 19 Apr 2002 22:44:47 +0200
break statement in xsl
Dung, Ming-tzung wrote:
Hi,
    I wonder whether the XSLT has the instruction like the "break" statement
in C/Java language inside the loop. If no such instruction, any design idiom
can solve this problem?   Thanks in advance!!

You have to get rid of the habit of viewing xsl:for-each as being a loop. It is not a loop. Think of it as a statement which applies a function to each element of a list (or an array), in parallel. Because it's not a loop, you can't break out of it. Instead you have to construct the correct list of nodes you want to apply the for-each body to right at the beginning.

Instead of
 for( d in data) {
   if( d.total > max ) {
     break;
   }
   do-stuff;
 }

you have to select the right node set (which is not trivial
in this case):
  <xsl:for-each select="data[total &gt; $max][1]/preceding-sibling::data">
    <stuff/>
  </xsl:for-each>
In most cases, selecting the correct set of nodes
is much easier.

HTH
J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

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
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.