I would like to have xpath, that obtains nodes, that don't have ancestor, which is first descendant of specific node.
Let's assume we have xml document like this:
<a>
<b>This node</b>
<c>
<a>
<b>not this</b>
<g>
<b>not this</b>
</g>
</a>
<a>
<b>This node</b>
<c/>
</a>
</c>
</a>
<a>
<c>
<a>
<b>not this</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
<a>
<b>This node</b>
</a>
</c>
</a>
<d>
<b>This node</b>
</d>
I would like to select all b nodes in document that don't have as their ancestor node //a/c/a[1].
Use this XPath expression:
This selects all
b
elements in the document that don't have ancestora
that has a parentc
that has parenta
and thea
ancestor that has parentc
is not the firsta
child of its parent.Given the following XML document (based on the provided, but made well-formed and also put identifying text in the nodes that should be selected):
exactly the wanted 6
b
elements are selected.Verification using XSLT:
when this transformation is applied on the above XML document, exactly the wanted
b
elements are selected and copied to the output. The wanted, correct result is produced: