I’ve got the following XML Code:
<!-- language: xml -->
<Stats>
<Stat>
<Data Name="Value">63.76</Data>
<Data Name="Entity">first</Data>
</Stat>
<Stat>
<Data Name="Value">51.23</Data>
<Data Name="Entity">second</Data>
</Stat>
<Stat>
<Data Name="Value">46.1</Data>
<Data Name="Entity">third</Data>
</Stat>
<Stat>
<Data Name="Value">61.21</Data>
<Data Name="Entity">first</Data>
</Stat>
</Stats>
I want to filter only where ‘Data[@Name=’Entity’]. Using xpath: /Stats/Stat/Data[@Name="Entity"] returns:
first
second
third
first
But I want the results to be unique. So I only get:
first
second
third
EDIT: I need this to work for xpath version 1.0.
Use this XPath 1.0 expression:
XSLT – based verification:
when this transformation is applied on the following XML document (produced by correcting the non-well-formed provided text):
the above XPath expression is evaluated and the selected nodes are copied to the output:
Note: If you just need the text nodes (“first”, “second” and “third”), just use this single XPath expression: