Let’s say I have the following xml:
<one>
<two>
<three>
<three>
foo
</three>
<four />
<three>
bar
<four />
</three>
</three>
</two>
</one>
What XPath query can I write that will return only these nodes:
<three>
foo
</three>
and
<three>
bar
<four />
</three>
but not this one:
<three>
<three>
foo
</three>
<four />
<three>
bar
<four />
</three>
</three>
I’ve tried this:
//three/descendant-or-self::*/text()/ancestor::three
but it returns the one I don’t want. I also can’t assume that this is the exact structure of the xml, so I don’t think that the .. operator will work. Essentially, I want the youngest ancestor of the text nodes that’s of type three.
Any suggestions?
I think
//three[text() and not (descendant::three)]will do what you want.