xPath get sibling nodes when node text contains



Having a text xml code like the following:



<meters>
<metric>
<n>one</n>
<k>two</k>
<m>three</m>
<k>four</k>
</metric>
<metric>
<n>one</n>
<k>five</k>
<m>six</m>
<k>seven</k>
</metric>
<metric>
<n>two</n>
<k>eight</k>
<m>nine</m>
<k>ten</k>
</metric>
</meters>


I would like to get all the sibling node text where node 'n' contains the text "one".


Tried:



//*[contains(text(),"one")]/follow-sibling::*/
//*[contains(.,"one")]/follow-sibling::*/


T //n[contains(.,"one")]/


I want it to return something like this



<k>two</k>
<m>three</m>
<k>four</k>
<k>five</k>
<m>six</m>
<k>seven</k>"

No comments:

Post a Comment