Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to count number of attributes used in XML document and their values.

For example, in this document

HTML
<Records>
    <item type="someAtt1">value1</item>
    <item type="someAtt1">value2</item>
    <item role="someRole2">value3</item>
    <item role="someRole">value4</item>
    <item genre="someGenre">value5</item>
</Records>
<Records>
    <item genre="someGenre2">value2</item>
    <item role="someRole">value3</item>
    <item type="someAtt2">value4</item>
    <item role="someRole1">value5</item>
</Records>


The desired results is as follows:

type (someAtt1) =2
type (someAtt2) =1
role (someRole) =2
role (someRole1)=1
role (someRole2) =1
genre (someGenre) = 1
genre (someGenre2) = 1

Thanks
Posted
Comments
Zoltán Zörgő 25-Jan-15 8:04am    
Do you really need this in XSLT? Do you have 2.0 at least? It is just not for that. Don't you have any programable layer above? The problem is, that you need to have strong assumptions about your XML to use XSLT. The fewer assumtions you can count on, as complicated the transformation will become - if any.
Have a look here: http://docstore.mik.ua/orelly/xml/xslt/ch06_02.htm. It has some similarities with your requirement, as it is about grouping also... well, I will try to figure out something, but still... it is just not for that...
Eilia98 26-Jan-15 3:28am    
Thanks for advice.
Zoltán Zörgő 26-Jan-15 5:42am    
Well, I haven't succeeded until now, I I doubt I will have much more time to deal with it. So, again: isn't there any other programmatic way you can use? Why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900