sandeep kairamkonda
sandeep kairamkonda

Reputation: 85

XSLT How to get total Number of occurrences of an element of multiple parents

I have a XML need to get the count of occurrences of an element

<lines>
<line>
 <accountings>
  <accounting>
    <account>
      <seg1>value1</seg2>
    </account>
  </accounting>
  <accounting>
    <account>
      <seg1>value2</seg2>
    </account>
  </accounting>
 </accountings>
 </line>
 <line>
<accountings>
 <accounting>
    <account>
      <seg1>value3</seg2>
    </account>
  </accounting>
  </accountings>
 </line>
 <line>
 <account>
    <seg1>value4</seg1>
 </account>
 </line>
</lines>

In the Above xml there are total 4 <account> elements

I need the output as 4, but whenever I try for-each or for-each-group and count on each iterate I get value as 1111, atleast I need a way to add all the counts.

Upvotes: 2

Views: 1021

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

No need for looping or grouping, just use

count(//account)

Upvotes: 5

Related Questions