XPath to identify a parent based on two related children -
using following example, trying create xpath identify id of apples branchid matches id of branch, treeid doesn't match branch's treeid.
for instance: //growth[@type="apple"][branchid=//branch/@id]/@id - results granny empire gala
and //growth[@type="apple"][treeid!=//branch/treeid]/@id - results granny empire gala
but want query return: granny
<xml> <growth type="apple" id="granny"> <branchid>abcd</branchid> <treeid>456</treeid> </growth> <growth type="apple" id="empire"> <branchid>abcd</branchid> <treeid>123</treeid> </growth> <growth type="apple" id="gala"> <branchid>efgh</branchid> <treeid>456</treeid> </growth> <growth type="flower" id="white"> <branchid>efgh</branchid> <treeid>123</treeid> </growth> <growth type="flower" id="yellow"> <branchid>abcd</branchid> <treeid>456</treeid> </growth> <branch id="abcd"> <treeid>123</treeid> </branch> <branch id="efgh"> <treeid>456</treeid> </branch> <tree id="123" /> <tree id="456" /> <tree id="789" /> </xml>
so required item(s) (where branchid/treeid pair not exist in branch element) have different index values branchid in list of //branch/@id values , treeid in list of //branch/treeid values...
//growth[@type="apple"][index-of(//branch/@id,branchid)!=index-of(//branch/treeid,treeid)]/@id granny
nice question give little grey cells exercise on friday lunchtime :o)
Comments
Post a Comment