Re: conditional counting of elements

Subject: Re: conditional counting of elements
From: Michel CASABIANCA <casa@xxxxxx>
Date: 08 Mar 2000 23:07:46 +0100
Hello

PAPINENI Sivaprakash <SPapinen@xxxxxxxxxx> 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@xxxxxx        | 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


Current Thread