This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Avoiding the use of count when needing "at least one"
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] Avoiding the use of count when needing "at least one"
- From: "Anchal Jain" <ajain at metreo dot com>
- Date: Tue, 9 Jan 2001 14:51:16 -0800
- Reply-To: xsl-list at lists dot mulberrytech dot com
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