MartinKahn
MartinKahn

Reputation: 137

Implementing a counter using xslt

I have this xml

<?xml version="1.0" encoding="UTF-8"?>
<Input>   
<Properties>
  <Type Name="Type1">
    <Property NAME="Prop1"/>
    <Property NAME="Prop2"/>
    <Property NAME="Prop3"/>
  </Type>
  <Type Name="Type2">
    <Property NAME="Prop4"/>
    <Property NAME="Prop5"/>
  </Type>
  <Type Name="Type3">
    <Property NAME="Prop6"/>
  </Type>
  <Type Name="Type4">
    <Property NAME="Prop7"/>
    <Property NAME="Prop8"/>
  </Type>
  <Type Name="Type5">
    <Property NAME="Prop9"/>
  </Type>
</Properties>
 </Input>

I need to implement a counter using xslt that will give me the total Property count under all types (in this case 9 ). Can it be done in xslt?

Upvotes: 1

Views: 349

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243459

I need to implement a counter using xslt that will give me the total Property count under all types (in this case 9 ).

No, you don't need to implement a counter.

Just use:

count(/*/*/Type/Property)

To answer your next question:

Can it be done in xslt?

No, mutable variables are not possible in a functional language (a category to which XSLT belongs) -- by definition. And having mutable variables is not necessary.

Any problem that can be solved in an imperative way (with mutable variables), can also be solved in a functional way -- without using mutable variables.

Upvotes: 1

Related Questions