popParams(xctxt);
popParams(xctxt, savedSearchStart);
  public void transformSelectedNodes(          TransformerImpl transformer, Node sourceNode, ElemTemplateElement template, QName mode)            throws TransformerException  {    try    {      boolean rdebug = TransformerImpl.S_DEBUG;      XPathContext xctxt = transformer.getXPathContext();      XPath selectPattern = getSelectOrDefault();      XObject selectResult = selectPattern.execute(xctxt, sourceNode, this);            if (rdebug)        transformer.getTraceManager().fireSelectedEvent(sourceNode, this,                                                        "test", selectPattern, selectResult);            Vector keys = transformer.processSortKeys(this, sourceNode);      NodeIterator sourceNodes = selectResult.nodeset();      // Sort if we need to.      if (null != keys)        sourceNodes = sortNodes(xctxt, keys, sourceNodes);      pushParams(transformer, xctxt, sourceNode, mode);      // Push the ContextNodeList on a stack, so that select="position()"      // and the like will work.      // System.out.println("pushing context node list...");      SourceLocator savedLocator = xctxt.getSAXLocator();      xctxt.pushContextNodeList((ContextNodeList) sourceNodes);      transformer.pushElemTemplateElement(null);      ResultTreeHandler rth = transformer.getResultTreeHandler();      StylesheetRoot sroot = getStylesheetRoot();      TemplateList tl = sroot.getTemplateListComposed();      // StylesheetComposed stylesheet = getStylesheetComposed();      StackGuard guard = transformer.getStackGuard();      boolean check = (guard.m_recursionLimit > -1);      boolean quiet = transformer.getQuietConflictWarnings();      boolean needToFindTemplate = (null == template);      try      {        Node child;        while (null != (child = sourceNodes.nextNode()))        {          if (needToFindTemplate)          {            template = tl.getTemplate(xctxt, child, mode, -1, quiet);            // 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 (child.getNodeType())              {              case Node.DOCUMENT_FRAGMENT_NODE :              case Node.ELEMENT_NODE :                template = sroot.getDefaultRule();                break;              case Node.CDATA_SECTION_NODE :                if (child.isSupported(SaxEventDispatch.SUPPORTSINTERFACE, "1.0"))                {                  ((SaxEventDispatch) child).dispatchSaxEvent(rth);                }                else                {                  rth.startCDATA();                  String data = child.getNodeValue();                  rth.characters(data.toCharArray(), 0, data.length());                  rth.endCDATA();                }                continue;              case Node.TEXT_NODE :                if (child.isSupported(SaxEventDispatch.SUPPORTSINTERFACE, "1.0"))                {                  ((SaxEventDispatch) child).dispatchSaxEvent(rth);                }                else                {                  String data = child.getNodeValue();                  rth.characters(data.toCharArray(), 0, data.length());                }                continue;              case Node.ATTRIBUTE_NODE :                String data = child.getNodeValue();                rth.characters(data.toCharArray(), 0, data.length());                continue;              case Node.DOCUMENT_NODE :                template = sroot.getDefaultRootRule();                break;              default :                // No default rules for processing instructions and the like.                continue;              }            }          }          // If we are processing the default text rule, then just clone           // the value directly to the result tree.          try          {            transformer.pushPairCurrentMatched(template, child);            if (check)              guard.push(this, child);            // Fire a trace event for the template.            if (rdebug)              transformer.getTraceManager().fireTraceEvent(child, mode,                                                           template);            // And execute the child templates.            if (template.isCompiledTemplate())              template.execute(transformer, child, mode);            else            {              // Loop through the children of the template, calling execute on               // each of them.              for (ElemTemplateElement t = template.m_firstChild; t != null;                   t = t.m_nextSibling)              {                xctxt.setSAXLocator(t);                transformer.setCurrentElement(t);                t.execute(transformer, child, mode);              }            }          }          finally          {            transformer.popCurrentMatched();            if (check)              guard.pop();          }        }      }      finally      {        xctxt.setSAXLocator(savedLocator);        xctxt.popContextNodeList();        transformer.popElemTemplateElement();        popParams(xctxt);        // if(null != sourceNodes)        //  sourceNodes.detach();      }    }    catch(SAXException se)    {      transformer.getErrorListener().fatalError(new TransformerException(se));    }  }