I have a xml like this,
<doc>
<chap>
<sec originator="ABC">
<app originator="body">
<sec originator="body">
<p>text</p>
</sec>
</app>
</sec>
</chap>
<chap>
<chap>
<app originator="DEF">
<sec originator="body">
<sec>
<p>text2</p>
</sec>
</sec>
</app>
</chap>
</chap>
<sec originator="GHI">
<sec originator="body">
<p>text</p>
</sec>
</sec>
<app originator="KLM">
<sec>
<sec>
<p>text2</p>
</sec>
</sec>
</app>
</doc>
I have written template for <p> node and from that I need to get the most distance ancestor <sec> or <app> node originator attribute value.
My xpath is
//p/(ancestor::app[@originator][last()] | ancestor::sec[@originator][last()])/@originator
This will select originator attribute values ABC, body, DEF, body, GHI, KLM.. But what I need is ABC, DEF, GHI, KLM.
How can I change my xpath to get most distance <sec> or <app> node originator attribute value