Wednesday, October 28, 2009

Getting the nearest xpath ancestor

Given the following xml fragment:
1
2
3
4
5
<a>
<a>
<b/>
</a>
<a>

To find the nearest ancestor <a/> w.r.t <b/>, i use:

//b/ancestor::a[1]

That's all !!

No comments:

Post a Comment

Labels