Node root = node;
while (root.getParent() != null) {
root = root.getParent();
}
DocumentWrapper docWrapper = null;
if (docWrappers != null) docWrapper = (DocumentWrapper) docWrappers.get(root);
if (docWrapper == null) { // root has not been seen before
docWrapper = new DocumentWrapper(root, root.getBaseURI(), getStaticContext().getConfiguration());
// remember the DocWrapper for the given root so we can reuse it later
if (docWrappers != null) docWrappers.put(root, docWrapper);
}
return docWrapper.wrap(node);
}