Reputation: 161
I want to select all nodes (first children) of a root document ,/*/*
but my problem is selecting only the name of tag as a set.
for example :
`
<root>
<node1>X</node1>
<node1>Y</node1>
<node2>W</node2>
<node3>Z</node3>
<node3>K</node3>
<node4>V</node4>
</root>
`
I want as result only 'node1,node2,node3,node4'
without repeat of node name.
Thanks.
Upvotes: 0
Views: 83
Reputation: 122394
If you can guarantee that the elements with the same name will always be adjacent in the input XML then it's sufficient to pull out those elements whose name is not the same as their immediately preceding sibling (if any):
/root/*[not(name() = name(preceding-sibling::*[1]))]
If you can't guarantee this and instead need to check each element against all its preceding siblings, then I can't see a way to do this in a single XPath 1.0 expression - you'd have to have two nested predicates and there's no way to refer to the node being tested by the outer predicate when you're inside the inner one.
Upvotes: 2