How to use count operation in Node-set Function Using XPath in Xml

In this article I will explain count operation of node-set function.
  • 2618
Introduction

The count function of node-set returns the number of nodes in the node-sets arguments. If their are many number of nodes then the count function is used to count that number of nodes.

Syntax
 
number count(node-set)

Let us take an example

Example

code for example.xml

<?xml version="1.0" encoding="utf-8" ?>

<equation>

  <xyz x="11">

    <xyz x="12">

      <xyz>

        <abc>abc31</abc>

        <abc>abc32</abc>

      </xyz>

    </xyz>

  </xyz>

  <xyz x="11">

    <xyz x="12">

      <abc>abc21</abc>

      <abc>abc22</abc>

    </xyz>

  </xyz>

  <xyz x="11">

    <abc>abc11</abc>

    <abc>abc12</abc>

  </xyz>

  <xyz>

    <abc>abc03</abc>

    <abc>abc04</abc>

  </xyz>

</equation>

Now If I use the count function in xslt file like this

select="count(//xyz)"
select="count(//xyz[11])"
select="count(//xyz/abc)"

Output
7
4
8

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.