Make a tree from a flattened set of nodes

This is a problem posed by Jens Peterson on Stackoverflow
There is a larger test set accessible as
Approach Repetitions Average msec * XQuery length
Chris Wallace's solution 100 5.14 978
Chris Wallace's solution with intersect replaced by precedence operator. 100 5.68 911
Jens Erat's solution 100 7.01 1429
* relative times are more useful than absolute times. At present the execution time includes compilation of locally-declared functions although the code is cached.