This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Avoiding the use of count when needing "at least one"
- To: "Anchal Jain" <ajain at metreo dot com>
- Subject: Re: [xsl] Avoiding the use of count when needing "at least one"
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Wed, 10 Jan 2001 00:53:12 +0000
- CC: xsl-list at lists dot mulberrytech dot com
- Organization: Jeni Tennison Consulting Ltd
- References: <NEBBKGHBBKDLPKMDGHHLAECCCBAA.ajain@metreo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Anchal,
> I would like to print out a certain string if there is at least one
> EmployeeName element that has a Manager type and a different string
> if there isn't even one EmployeeName element that has a Manager
> Type.
>
[snip]
> <xsl:when test="count(EmployeeName[@Type='Manager']) != 0">
[snip]
The test that you're using there is exactly equivalent to:
EmployeeName[@Type='Manager']
The above XPath returns all the EmployeeName elements that have a
@Type attribute with a value of 'Manager'. When this node set is
evaluated as a boolean (e.g. in a 'test' attribute or in a predicate)
then it's counted as true if there any nodes in it, false if not.
Most good XSLT processors will perform some kind of optimisation that
stops and returns true after the first matching node is found.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list