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

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

Subject: Avoiding the use of count when needing "at least one"
From: "Anchal Jain" <ajain@xxxxxxxxxx>
Date: Tue, 9 Jan 2001 14:51:16 -0800
anchal jain
Sorry, if this question has already been asked and answered. Is there a way
of asking "at least one" exists in XSL?

For example, I have the following XML:

<Employees>
<EmployeeName Type="Manager">Jane</EmployeeName>
<EmployeeName Type="Staff">John</EmployeeName>
<EmployeeName Type="Staff">Paul</EmployeeName>
<EmployeeName Type="Manager">Jones</EmployeeName>
<EmployeeName Type="Assistant">Mary</EmployeeName>
</Employees>

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.

The only way I could think of doing it was:

<xsl:template match="Employees">
<xsl:choose>
<xsl:when test="count(EmployeeName[@Type='Manager']) != 0">
<xsl:text>There is at least one manager in the group.</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>There are no managers in the group.</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

This method causes the XSLT processor to count all the Name elements with
attribute 'Manager'. But I know the answer once the processor encounters the
first instance of Type='Manager'.

Thanks
Anchal


 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.