xctxt.setNamespaceContext(xslInstruction); template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, maxImportLevel, m_quietConflictWarnings);
template = null;
  public boolean applyTemplateToNode(ElemTemplateElement xslInstruction,  // xsl:apply-templates or xsl:for-each                                     ElemTemplateElement template,  // may be null                                             Node child, QName mode)                                                     throws TransformerException  {    short nodeType = child.getNodeType();    boolean isDefaultTextRule = false;    if (null == template)    {      int maxImportLevel;      boolean isApplyImports = ((xslInstruction == null)                                ? false                                : xslInstruction.getXSLToken()                                  == Constants.ELEMNAME_APPLY_IMPORTS);      if (isApplyImports)      {        maxImportLevel = xslInstruction.getStylesheetComposed().getImportCountComposed() - 1;      }      else      {        maxImportLevel = -1;      }      // Find the XSL template that is the best match for the       // element.              XPathContext xctxt = getXPathContext();      PrefixResolver savedPrefixResolver = xctxt.getNamespaceContext();      try      {        xctxt.setNamespaceContext(xslInstruction);        template = m_stylesheetRoot.getTemplateComposed(xctxt, child, mode, maxImportLevel,                                  m_quietConflictWarnings);      }      finally      {        xctxt.setNamespaceContext(savedPrefixResolver);      }      // If that didn't locate a node, fall back to a default template rule.      // See http://www.w3.org/TR/xslt#built-in-rule.      if (null == template)      {        switch (nodeType)        {        case Node.DOCUMENT_FRAGMENT_NODE :        case Node.ELEMENT_NODE :          template = m_stylesheetRoot.getDefaultRule();          break;        case Node.CDATA_SECTION_NODE :        case Node.TEXT_NODE :        case Node.ATTRIBUTE_NODE :          template = m_stylesheetRoot.getDefaultTextRule();          isDefaultTextRule = true;          break;        case Node.DOCUMENT_NODE :          template = m_stylesheetRoot.getDefaultRootRule();          break;        default :          // No default rules for processing instructions and the like.          return false;        }      }    }    // If we are processing the default text rule, then just clone     // the value directly to the result tree.    try    {      pushElemTemplateElement(template);      m_xcontext.pushCurrentNode(child);      pushPairCurrentMatched(template, child);      if (isDefaultTextRule)      {        switch (nodeType)        {        case Node.CDATA_SECTION_NODE :        case Node.TEXT_NODE :          m_resultTreeHandler.m_cloner.cloneToResultTree(child, false);          break;        case Node.ATTRIBUTE_NODE :        {          String val = ((Attr) child).getValue();          getResultTreeHandler().characters(val.toCharArray(), 0,                                            val.length());        }        break;        }      }      else      {        // Fire a trace event for the template.        if (TransformerImpl.S_DEBUG)          getTraceManager().fireTraceEvent(child, mode, template);        // And execute the child templates.        // 9/11/00: If template has been compiled, hand off to it        // since much (most? all?) of the processing has been inlined.        // (It would be nice if there was a single entry point that        // worked for both... but the interpretive system works by        // having the Tranformer execute the children, while the        // compiled obviously has to run its own code. It's        // also unclear that "execute" is really the right name for        // that entry point.)        m_xcontext.setSAXLocator(template);        if (template.isCompiledTemplate())          template.execute(this, child, mode);        else          executeChildTemplates(template, child, mode, true);      }    }    catch(org.xml.sax.SAXException se)    {      throw new TransformerException(se);    }    finally    {      m_xcontext.popCurrentNode();      popCurrentMatched();      popElemTemplateElement();    }    return true;  }