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

RE: Do something if no items in for-each meet criteria

Subject: RE: Do something if no items in for-each meet criteria
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 12 Sep 2003 11:21:58 +0100
xsl variable variable 1
There are two approaches.

(1) read the input twice

for-each select="xxx"
  yyy
/for-each
if (not(xxx)) message

(2) put the output in a variable

variable v
  for-each select="xxx"
    yyy
  /for-each
/variable
choose
 when test="$v=''" message /when
 otherwise copy-of select=$v /otherwise
/choose

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Peter Hollingsworth
> Sent: 12 September 2003 00:12
> To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Do something if no items in for-each meet criteria
> 
> 
> I'm trying to
>    1) go through a set of nodes
>    2) if any matches my criteria, display it
>    3) if NONE matches my criteria, display a message like "None"
> 
> For example, imagine this xml listing some animals:
> <animal>
>    <type>snake</type>
>    <furry>false</furry>
> </animal>
> <animal>
>    <type>fish</type>
>    <furry>false</furry>
> </animal>
> 
> and this XSL that lists all the ones with fur:
> The following animals are furry:<br/>
> <xsl:for-each select="animal">
>    <xsl:if test="furry = 'true'">
>      <xsl:value-of select="type"/><br/>
>    </xsl:if>
> </xsl:for-each>
> [if no animals were furry, print "None are furry"]  <---how 
> can I do this?
> 
> Any way I can accomplish what I'm trying to do on the last line above?
> 
> Thanks.
> 
> --Peter
> 
> 
>  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

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.