Reputation: 181
Here is my XML
<?xml version = '1.0' encoding = 'UTF-8'?>
<cmps>
<cmp>
<name>abc</name>
<id>302</id>
</cmp>
<cmp>
<name>abc</name>
<id>370</id>
</cmp>
<cmp>
<name>abc</name>
<id>073</id>
</cmp>
<cmp>
<name>abc</name>
<id>302</id>
</cmp>
<cmp>
<name>ab</name>
<id>370</id>
</cmp>
</cmps>
=================== In the above xml, want to find out all the duplicates based on name and id element. so this xml has one duplicate element which has same name and id. but below xpath expression shows two duplicate element , can somebody correct the expression...any help is appreciated
cmps//cmp[id= (following-sibling::cmp/id) and name= (following-sibling::cmp/name) ]
Output of above xpath expression:
<cmp>
<name>abc</name>
<id>302</id>
</cmp>
<cmp>
<name>abc</name>
<id>370</id>
</cmp>
Expected output :
<cmp>
<name>abc</name>
<id>302</id>
</cmp>
Upvotes: 0
Views: 566
Reputation: 11416
You can use not()
:
//cmps//cmp[not(id= (following-sibling::cmp/id)
and name = (following-sibling::cmp/name))]
Result:
<cmp>
<name>abc</name>
<id>302</id>
</cmp>
<cmp>
<name>abc</name>
<id>073</id>
</cmp>
<cmp>
<name>ab</name>
<id>370</id>
</cmp>
Upvotes: 1