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

RE: possible to mimic while-like behavior?

Subject: RE: possible to mimic while-like behavior?
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Fri, 17 Mar 2000 10:12:00 -0000
xslt while loop simulate
> e.g., speaking in a Perl-esque way, I want
>   while ($foo != "bar") {
>     blah
>   }
> 
> Is there any way to simulate, hack, or otherwise achieve this?

Pure XSLT is side-effect free, so the value of $foo cannot change within the
loop, therefore this construct would be of limited value. Saxon does provide
the extension element saxon:while, as has been mentioned, but it is only
useful in conjunction with extension functions or extension elements (such
as saxon:assign) that have side-effects. An example:

<div xmlns:tok="java.util.StringTokenizer">
<xsl:variable name="tokens" select="tok:StringTokenizer.new('a bag of
worms')"/>
<saxon:while test="tok:hasMoreTokens()">
   <word><xsl:value-of select="tok:nextToken($tokens)"></word>
</saxon:while>
</div>

Here nextToken() is an extension function that has a side-effect, namely
moving the current position.

Unlike xsl:for-each, saxon:while is strictly sequential. As David Carlisle
mentioned, you can't predict the order of execution of xsl:for-each. I don't
know of an XSLT processor that executes xsl:for-each non-sequentially, but
it's certainly permitted: hence the absence of an <xsl:break> instruction.

Mike Kay



 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.