This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: conditional counting of elements


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]