There's a bug in eXist's handling of reverse axes. According to XQuery
section 3.2.2, the context positions for reverse axes (e.g. "preceding" or
"ancestor") should be assigned in reverse document order. So, for example,
ancestor::* should always be equal to parent::*. Unfortunately, AFAICT,
eXist sorts all results into document order before evaluating predicates, so
that ancestor::* always returns the root node. I've attached a unit test
patch that demonstrates the bug.
Wolfgang, perhaps you can take a look at this while fixing the position