I am trying to use xpath to select all the node elements that contain a child element that has any value for the restriction attribute other than an empty string.
Here is my xml:
<nodes code="C">
<node code="A">
<child restriction="" />
<child restriction="value" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
</node>
<node code="B">
<child restriction="value" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
</node>
<node code="C">
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
<child restriction="" />
</node>
</nodes>
My working xpath is:
nodes/node[(child/@restriction and string-length(child/@restriction) > 0)]
This only returns node B, presumably because B is the only element where the restriction value appears first. My aim is to return both B and A but not C.
Can someone point out where I've gone wrong?