This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Avoiding the use of count when needing "at least one"


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]