}
  void doApply(Stylesheet stylesheet, QName mode,             Node context, int pos, int len,             Node parent, Node nextSibling)    throws TransformerException  {    Node result = null;    Document doc = (parent instanceof Document) ? (Document) parent :      parent.getOwnerDocument();    short nodeType = source.getNodeType();    if (nodeType == Node.ATTRIBUTE_NODE &&        parent.getFirstChild() != null)      {        // Ignore attributes added after child elements      }    else      {        // Namespace aliasing        if (nodeType == Node.ELEMENT_NODE)          {            String prefix = source.getPrefix();            if (prefix == null)              {                prefix = "#default";              }            String resultPrefix =              (String) stylesheet.namespaceAliases.get(prefix);            if (resultPrefix != null)              {                if ("#default".equals(resultPrefix))                  {                    resultPrefix = null;                  }                String uri = source.lookupNamespaceURI(resultPrefix);                String name = source.getNodeName();                // Create a new element node in the result document                result = doc.createElementNS(uri, name);                // copy attributes                NamedNodeMap srcAttrs = source.getAttributes();                NamedNodeMap dstAttrs = result.getAttributes();                int l = srcAttrs.getLength();                for (int i = 0; i < l; i++)                  {                    Node attr = srcAttrs.item(i);                    if (!Stylesheet.XSL_NS.equals(attr.getNamespaceURI()))                      {                        attr = attr.cloneNode(true);                        attr = doc.adoptNode(attr);                        dstAttrs.setNamedItemNS(attr);                      }                  }              }          }        if (result == null)          {            // Create result node            result = source.cloneNode(false);            // Remove any XSL attributes            NamedNodeMap attrs = result.getAttributes();            if (attrs != null)              {                int l = attrs.getLength();                for (int i = 0; i < l; i++)                  {                    Node attr = attrs.item(i);                    if (Stylesheet.XSL_NS.equals(attr.getNamespaceURI()))                      {                        attrs.removeNamedItem(attr.getNodeName());                        i--;                        l--;                      }                  }              }            Node result2 = doc.adoptNode(result);            if (result2 == null)              {                String msg = "Error adopting node to result tree: " +                  result + " (" + result.getClass().getName() + ")";                DOMSourceLocator l = new DOMSourceLocator(context);                throw new TransformerException(msg, l);              }            result = result2;          }        if (nextSibling != null)          {            parent.insertBefore(result, nextSibling);          }        else          {            parent.appendChild(result);          }        if (nodeType == Node.ELEMENT_NODE)          {            stylesheet.addNamespaceNodes(source, result, doc,                                         elementExcludeResultPrefixes);          }        // children        if (children != null)          {            children.apply(stylesheet, mode,                           context, pos, len,                           result, null);          }      }    // next sibling    if (next != null)      {        next.apply(stylesheet, mode,                   context, pos, len,                   parent, nextSibling);      }  }