count()- Takes a node-set argument and returns a value equal to the number of nodes in the node-set : count « XSLT stylesheet « XML Tutorial






File: Data.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="Transform.xslt" type="text/xsl"?>
<europe>
  <state>Belgium</state>
  <state>Germany</state>
  <state>Finland</state>
  <state>Greece</state>
  <state>San Marino</state>
  <state>Switzerland</state>
</europe>


File: Transform.xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="text" />

  <xsl:template match="europe">
    <xsl:text>&#10;Total Number of States: </xsl:text>
    <xsl:value-of select="count(state)" />
    <xsl:text>&#10;&#10;</xsl:text>
    <xsl:apply-templates select="state">
      <xsl:sort />
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="state">
    <xsl:text> - </xsl:text>
    <xsl:apply-templates />
    <xsl:text>&#10;</xsl:text>
  </xsl:template>

</xsl:stylesheet>

Output:

Total Number of States: 6

 - Belgium
 - Finland
 - Germany
 - Greece
 - San Marino
 - Switzerland








5.10.count
5.10.1.count()- Takes a node-set argument and returns a value equal to the number of nodes in the node-set
5.10.2.Use count function in math calculation
5.10.3.Count matches
5.10.4.Count node
5.10.5.count elements which occured in XML source
5.10.6.The count function returns the number of nodes in the argument node-set.