Get the count of nodes

Other topics

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

Syntax:

  • count(node-set)

Parameters:

functionreturns
counttotal number of nodes in the node set

Contributors

Topic Id: 4463

Example Ids: 15596,15597

This site is not affiliated with any of the contributors.