Parsing and counting using XSLT
Posted: Wed Jan 23, 2008 2:26 pm
Hello!
I m trying to transform a XML file into new XML file .
Description:
Each unique value from the <name> elements in the input record are to be uniqued, alphabetized and stored with a "count" attribute. The new "count" attribute provides the number of occurrences of that value .Must parse and input element on semi-colon if this delimits a list of values.
input XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<School>
<student rec='1'>
<name>Robart J</name>
</student>
<student rec='2'>
<name>Alex M; Peter R</name>
</student>
<student rec='3'>
<name>Alex M;Robart J; Dave T</name>
</student>
</School>
Output XML should be like..
<School>
<name count='2'>Robart J</name>
<name count='2'>Alex M</name>
<name count='1'>Peter R</name>
<name count='1'>Dave T</name>
</School>
I am using XSLT 2.0 processor. I just can't work it out. Is this even possible with XSL? Or is there a
better way of doing the substitution that I'm missing? Please let me know if it is possible in XSLT 1.0 ….
Thanks in advance
Manish
I m trying to transform a XML file into new XML file .
Description:
Each unique value from the <name> elements in the input record are to be uniqued, alphabetized and stored with a "count" attribute. The new "count" attribute provides the number of occurrences of that value .Must parse and input element on semi-colon if this delimits a list of values.
input XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<School>
<student rec='1'>
<name>Robart J</name>
</student>
<student rec='2'>
<name>Alex M; Peter R</name>
</student>
<student rec='3'>
<name>Alex M;Robart J; Dave T</name>
</student>
</School>
Output XML should be like..
<School>
<name count='2'>Robart J</name>
<name count='2'>Alex M</name>
<name count='1'>Peter R</name>
<name count='1'>Dave T</name>
</School>
I am using XSLT 2.0 processor. I just can't work it out. Is this even possible with XSL? Or is there a
better way of doing the substitution that I'm missing? Please let me know if it is possible in XSLT 1.0 ….
Thanks in advance
Manish