1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Dimitre. I will have to get started with the concepts of functional language.
@MartinKahn, You are welcome. I recommend some of the books on XSLT and XPath contained in this answer: stackoverflow.com/a/341589/36305

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.