|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: possible to mimic while-like behavior?
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








