xpath

Get the count of nodes

Syntax#

  • count(node-set)

Parameters#

function returns
count total number of nodes in the node set
## Remarks#
We can use this in combination of other functions and axes to suit our needs.
## How many children does Goku have?
XML
<Goku>
    <child name="Gohan"/>
    <child name="Goten"/>
</Goku>

XPATH

count(/Goku/child)

OUTPUT

2.0

How many plants are there in the house?

XML

<House>
    <LivingRoom>
        <plant name="rose"/>
    </LivingRoom>
    <TerraceGarden>
        <plant name="passion fruit"/>
        <plant name="lily"/>
        <plant name="golden duranta"/>
    </TerraceGarden>
</House>

XPATH

count(/House//plant)

OUTPUT

4.0

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow