Saturday, 3 January 2015

Fetching parent attribute for optional attributes in XPath




<?xml version="1.0" encoding="utf-8"?>
<client name="test">
<projects active="true">
<project id="pr1" active="false" />
<project id="pr2" active="true" />
<project id="pr3" />
</projects>
</client>


For the above I need to fetch the project having active="true" in case it's been set at element level. If it is not then I need to go to parent element and fine the active element and check it.


We need to get all the project element hence this should return



<project id="pr2" />
<project id="pr3" />


I used the //project/ancestor-or-self::node()/@active[position()=1] but its not working.


Please help.


No comments:

Post a Comment