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

RE: firing on more than one match

Subject: RE: firing on more than one match
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Fri, 17 Oct 2003 13:05:01 -0400
xslt more than one match
[Ronald Kent Gibson]

> I have something like this, ie there are more is more than 
> one node that is
> named ruledef, and I want my condition to fire when any of 
> these things are
> equal to the condition.
> 
> <xsl:when test="/ruledef[1]/@pageeject = 'yes'">
> 
> </xsl:when>
> 
> 
> Seems like a loop would be good here, but no loops in xslt.
> 
> I don't thinkr recursion will help, either. So can anyone 
> kindly give me
> some suggestions, thanks and enjoy the weekend.
> 
 
Basically, just select the node set that you want.  Something like this
is simple (I am assuming that the ruledef elements are immediate
children of a "root" element) -

<xsl:template match="/root">
<results>
<xsl:apply-templates select='ruledef[@pageeject="yes"]' mode='eject'/>
</results>
</xsl:template>

<xsl:template match='ruledef' mode='eject'>
   ---Fire rule here ---
</xsl:template>

Your example shows one of the really nice things about xslt, but one
that can be surprising to newcomers.  The select expression applies the
test to each candidate node, and returns only the set of nodes that pass
the test.  So you do not need to "loop" or do anything else - the system
just automatically does what you want (you _could_ write a "loop" in
several ways, including using xsl:for-each, but there is no point in
doing so in this case).

BTW, I only used a "mode" attribute in case you might want to have other
templates for ruledef nodes besides the pageeject template.  If you do
not, you could omit the "mode" attributes in both places.

Cheers,

Tom P

 

 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.