Subject: RE: [xsl] Do something if no items in for-each meet criteria From: "Michael Kay" <mhk@xxxxxxxxx> Date: Fri, 12 Sep 2003 11:16:02 +0100 |
This code is wrong, it produces no output if one or more furry animals are found. Michael Kay > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Xia Li > Sent: 12 September 2003 00:57 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: RE: [xsl] Do something if no items in for-each meet criteria > > > > Hi, > Here is a possible solution, create a variabe to record > the result of "for-each" statement and test the length of the > variable. It might not be the perfect one. but it can get the > desired result. > > <xsl:transform xmlns:xsl='http://www.w3.org/1999/XSL/Transform' > version='1.0' > xmlns:lang='en' > > > <xsl:template match="/"> > <xsl:variable name="noFurry"> > <xsl:for-each select="//animal"> > <xsl:if test="furry = 'true'"> > <xsl:value-of > select="type"/><br/> > </xsl:if> > </xsl:for-each> > </xsl:variable> > > <xsl:if test="string-length($noFurry) = 0"> > <xsl:message>None are furry</xsl:message> > </xsl:if> > </xsl:template> > </xsl:transform> > > Lisa > > Software Engineer > Galdos Systems Inc > > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of > Peter Hollingsworth > Sent: Thursday, September 11, 2003 4:12 PM > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx > Subject: [xsl] 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 > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Storing and retrieving ht, Michael Kay | Thread | [xsl] Re: Do something if no items , Dimitre Novatchev |
RE: [xsl] TrAX API and xsl:message, Michael Kay | Date | RE: [xsl] how to: Conditionally cal, Michael Kay |
Month |