XSLT and XPath selecting distinct nodes
It is a complicated task to select distinct nodes or to use grouping useing xslt. There are no simple syntax to write this type XPath query.
The work arround is quite difficult to remember, thats why i decided to duplicate internet content in my blog.
Let’s say, that the XML source is:
[root]
[MyData attribute1="15" attribute2="value1"/]
[MyData attribute1="14" attribute2="value2"/]
[MyData attribute1="12" attribute2="value3"/]
[MyData attribute1="15" attribute2="value4"/]
[MyData attribute1="14" attribute2="value5"/]
[MyData attribute1="12" attribute2="value6"/]
[MyData attribute1="15" attribute2="value7"/]
[MyData attribute1="15" attribute2="value8"/]
[/root]Lets say, that the task is to select distinct nodes grouping by attribute1.The Xpath will look like this:
//MyData[not(@attribute1=preceding-sibling::MyData/@attribute1)]/@attribute1
Thank you man!! I really need it.
Comment by Jairo Velasco — July 26, 2009 @ 10:01 pm
hi, this works fine without namespaces. can you please give a sample how to use this with a xml
which has namespaces.
thanks
Madushan
Comment by Madushan — October 19, 2009 @ 6:51 am