|
Subject: RE: possible to mimic while-like behavior? From: Kay Michael <Michael.Kay@xxxxxxx> Date: Fri, 17 Mar 2000 10:12:00 -0000 |
> 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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: possible to mimic while-like be, Mike Brown | Thread | Are Xalan compiled XSLT's thread-sa, Brian Dupras |
| Determining the of attribute values, nigel . byrnes | Date | Re: Determining the of attribute va, David Carlisle |
| Month |