Hi Rob,
I found this solution [1] but I was wondering if also a solution is possible that makes use of the ancestor being a reverse-axis[ 2].
[ 1] ( $element/ancestor::*/child::*[ @ID = $refID] ) [ last()]
You probably need two id tests:
$element/ancestor::*[*/@ID = $refID][1]/*[@ID = $refID]
I guess it depends mostly on the input if the first or second alternative will be faster.
Hope this helps, Christian