Hi, I think I bumped into a bug (on 8.0 snapshot) let $input := <ul> <li id="first">item 1</li> <li>item 2</li> <li id="last">item 3</li> </ul> return outermost(( $input//li[@id = 'last'], $input//li, $input//li[@id = 'first'] )) => <li id="first">item 1</li> <li>item 2</li> <li id="last">item 3</li> <li id="last">item 3</li> <li id="last">item 3</li> This is in document order but duplicates are not eliminated. The same happens with fn:innermost. According to the spec[1] "takes as input a sequence of nodes, and returns every node within the sequence that does not have another node within the sequence as an ancestor; the nodes are returned in document order with duplicates eliminated." [1] http://www.w3.org/TR/xpath-functions-30/#func-outermost --Marc