Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath to find duplicate node values

Tags:

xml

xpath

I have following xml file:

<Dictionary>
   <words>
       <word>AM</word>       
   </words>
   <words>
       <word>AN</word>
   </words>
   <words>
       <word>AN</word>
   </words>
</Dictionary>

I need xpath to find duplicate word nodes like in above "AN" is duplicate. I tried following from web search but it did not work:

/*/*[index-of(/*/*/word(), word())[2]]
like image 706
NoviceMe Avatar asked Jan 05 '18 20:01

NoviceMe


2 Answers

Select word that exists the same word before

/Dictionary/words/word[.= ../preceding-sibling::words/word]
like image 91
splash58 Avatar answered Oct 27 '22 15:10

splash58


With following axis:

//words/word[. = ./following::word]

https://www.w3.org/TR/1999/REC-xpath-19991116/#axes

like image 3
RomanPerekhrest Avatar answered Oct 27 '22 15:10

RomanPerekhrest