Reputation: 21
Consider the following XML example:
<books category="cat1">
<book id="1" ... />
<book id="2" ... />
<book id="3" ... />
</books>
If I use the XPath query /books/book/parent::*/@category
I am expected to receive
one row only:
cat1
However, how can the XPath query be modified to return
cat1
cat1
cat1
(meaning that I want to keep all duplicates).
Upvotes: 2
Views: 566
Reputation: 163322
The "/" operator in XPath automatically removes duplicates.
In XPath 1.0 there's a fundamental difficulty with your requirement: the only composite value supported in the data model is the node-set, and node-sets (being sets) cannot contain duplicates. So there's no such thing as a value containing duplicate nodes, and therefore no expression that will produce such a result.
Upvotes: 4
Reputation: 66724
In XPath 2.0 you could use a for
loop:
for $book in /books/book return $book/parent::*/@category
Upvotes: 4