Subject: [xsl] Avoiding the use of count when needing "at least one" From: "Anchal Jain" <ajain@xxxxxxxxxx> Date: Tue, 9 Jan 2001 14:51:16 -0800 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Testing strings for null, Jeni Tennison | Thread | Re: [xsl] Avoiding the use of count, Jeni Tennison |
Re: [xsl] Non-English character pro, Mike Brown | Date | [xsl] XALAN: exceptions from extens, McNeill, Keith D. |
Month |