Just for the sake of completion, the authoritative answer is herehttp://www.w3.org/TR/xpath/#predicates : "The proximity position of a member of a node-set with respect to an axis is defined to be the position of the node in the node-set ordered in document order if the axis is a forward axis and *ordered in reverse document order if the axis is a reverse axis*. The first position is 1."
Ah, okay. I didn't catch that you wanted "the nearest ancestor with a
particular name." In that case then I think you are golden. If there is a chance that the element itself is a div1 element, then you will want to use ancestor-or-self instead, but otherwise I think you have it right.
Hopefully, I will never have to find the nearest div for a div in this collection, the objective was to locate the smallest container for an infringing non-container (ie, not a div) element. So I think I'm done here.
Thanks!