This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: conditional counting of elements
- To: xsl-list at mulberrytech dot com
- Subject: Re: conditional counting of elements
- From: Michel CASABIANCA <casa at sdv dot fr>
- Date: 08 Mar 2000 23:07:46 +0100
- Cc: "'XSL-List at mulberrytech dot com'" <XSL-List at mulberrytech dot com>
- References: <8234CF257FAAD311A690009027B1003A669AFB@hqex01>
- Reply-To: xsl-list at mulberrytech dot com
Hello
PAPINENI Sivaprakash <SPapinen@CBSINC.com> writes:
> Sample Xml file:
>
> <?xml version="1.0"?>
> <company>
> <department id="1">
> <item>book</item>
> </department>
> <department id="2">
> <item>table</item>
> </department>
> <department id="3">
> <item>book</item>
> </department>
> </company>
>
> I'm trying to count the number of 'departments' that have value 'book' for
> 'item' element in the above Xml using XSLT(the latest version of Xalan) and
> display it in html.
You can use such a stylesheet :
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:value-of select="count(//department[item='book'])"/>
</xsl:template>
</xsl:stylesheet>
--
+---------------------------+--------------------------------+
| Michel CASABIANCA | http://www.sdv.fr/pages/casa |
| mailto:casa@sdv.fr | Articles sur Java et XML |
| Développement Java et XML | Applications et Applets de Jeu |
+---------------------------+--------------------------------+
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list