When the S9API interface DocumentBuilder.wrap() is called, supplying as argument a node that is not a document node (for example an element), it's not clear what is supposed to happen. The JavaDoc says that the argument must be a document node. In fact, if it isn't a document node, the wrap() method returns a wrapper around the document node of the tree containing the supplied node. This is not exactly intuitive, and if the resulting node is supplied as the context item for evaluating a path expression, evaluation is likely to fail.
The method will be changed so that it returns a wrapper around the actual supplied node. A patch to this effect is being placed in Subversion.