[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: possible to mimic while-like behavior?
Subject: RE: possible to mimic while-like behavior? From: sara.mitchell@xxxxxxxxx Date: Thu, 16 Mar 2000 16:02:45 -0500 |
It's probably not the only way to do this, but there are two possibilities: 1. You simply want to do one thing when bar and another when not bar. What you need is two separate templates. For example: <xsl:for-each select="foo[not(bar)]"> blah </xsl:for-each> <xsl:for-each select="foo[bar]"> different blah </xsl:for-each> This works as long as the bar|not bar condition can be expressed in XPath. 2. The other answer is named templates or modes, such as: <xsl:for-each select="foo"> <xsl:choose> <xsl:when test="bar">blah</xsl:when> <xsl:otherwise> <xsl:call-template name="blort"/> </xsl:otherwise> </xsl:choose> </xsl:for-each> Where the "blort" named template does what you want. If what you want is "do blah until you find the first foo where not bar" there is probably a way to do that also, but I'll leave that to the more knowledgable and more gifted to fill in. Sara > -----Original Message----- > From: Carole E. Mah [mailto:carole@xxxxxxxxxxxxxxxxxx] > Sent: Thursday, March 16, 2000 11:59 AM > To: xsl-list@xxxxxxxxxxxxxxxx > Subject: possible to mimic while-like behavior? > > > > I know there are only two conditionals possible in xsl stylesheets, > <xsl:if> and <xsl:choose> (inside which one has <xsl:when> > ... </xsl:when> > and <xsl:otherwise>...</xsl:otherwise> with nesting allow). > > However, there is no "while" or "until". > > Imagine, > <xsl:for-each select="foo"> > <xsl:choose> > <xsl:when test="bar">blah</xsl:when> > <xsl:otherwise>blort</xsl:otherwise> > </xsl:choose> > </xsl:for-each> > > Now imagine that when the conditions are such that <xsl:otherwise> is > matched, one wants to break out of the <xsl:for-each>. > > 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? > > thanks again, > -carole > - - - - - - - - - - - - - - - - - - - - - - - - - > Carole E. Mah Carole_Mah@xxxxxxxxx > Senior Programmer/Analyst > Brown University Scholarly Technology Group > phn 401-863-2669 > fax 401-863-9313 > http://www.stg.brown.edu/ > personal: http://www.stg.brown.edu/~carolem/ > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: possible to mimic while-like be, Arnold, Curt | Thread | RE: possible to mimic while-like be, Carole E. Mah |
RE: possible to mimic while-like be, Arnold, Curt | Date | Re: Microsoft XSL and Conformance, Steve Muench |
Month |
Keywords