code: private void mergeExtensionsIntoDocument(Node target, Node extensions) throws Exception {
          final XPathFactory factory = XPathFactory.newInstance();
          final NodeList nodes = (NodeList) factory.newXPath().evaluate("//extensions", extensions, XPathConstants.NODESET);
          for (int i = 0; i < nodes.getLength(); i++) {
              final Node extensionNode = nodes.item(i);
              String nameBasedXpath =  DomUtils.getNameBasedXPath(extensionNode, false);
              log.debug("Processing extension node: " + nameBasedXpath);
  
              final NodeList targetNodes = (NodeList) factory.newXPath().evaluate(nameBasedXpath, target, XPathConstants.NODESET);
              if (targetNodes.getLength() != 1) {
                  throw new IllegalArgumentException("XPath "+nameBasedXpath+" not found in target");
              }
              Node targetNode = targetNodes.item(0);
              Node importedNode = targetNode.getOwnerDocument().importNode(extensionNode, true);
              targetNode.appendChild(importedNode);
          }
      }
docs: Weave the extensions defined in the extensions doc into the target.