This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: possible to mimic while-like behavior?
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: possible to mimic while-like behavior?
- From: Kay Michael <Michael dot Kay at icl dot com>
- Date: Fri, 17 Mar 2000 10:12:00 -0000
- Reply-To: xsl-list at mulberrytech dot com
> 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