[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Break the For-each loop


Subject: Re: [xsl] Break the For-each loop
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 9 Sep 2005 10:51:13 +0100

> So how do I break the loop after I have
> found the first apple?

You never break out of a for loop in xslt. It is best to assume that you
are using a massively parallel machine and all items in the loop are
executed _in parallel_ and assembled into the final output in a
specified order which might be totally unrelated to the order in which
they are evaluated. (Even if in fact you are on a sequential machine an
XSLT compiler may (and some do) execute the items in orders which don't
correspond to the natural order that you might expect.

So don't break the loop: just select the items that you want to process,
for example if you want to process all the children up to and including
the first apple do

<xsl:for-each select="apple[1]/preceding-sibling::*|apple[1]">

David



________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


Current Thread
Keywords