{
  void doApply(Stylesheet stylesheet, QName mode,             Node context, int pos, int len,             Node parent, Node nextSibling)    throws TransformerException  {    if (children != null)      {        // Set current template to null        Template saved = stylesheet.currentTemplate;        stylesheet.currentTemplate = null;        Object ret = select.evaluate(context, pos, len);        //System.err.println(toString() + ": " + context+" -> "+ret);        if (ret instanceof Collection)          {            Collection ns = (Collection) ret;            List list = new ArrayList(ns);            if (sortKeys != null)              {                for (Iterator i = sortKeys.iterator(); i.hasNext(); )                  {                    SortKey sortKey = (SortKey) i.next();                    sortKey.init(stylesheet, mode, context, pos, len, parent,                                 nextSibling);                  }                Collections.sort(list, new XSLComparator(sortKeys));              }            else              {                Collections.sort(list, documentOrderComparator);              }            // Perform children for each node            int l = list.size();            int p = 1;            for (Iterator i = list.iterator(); i.hasNext(); )              {                Node node = (Node) i.next();                stylesheet.current = node;                children.apply(stylesheet, mode,                               node, p++, l,                               parent, nextSibling);              }          }        // Restore current template        stylesheet.currentTemplate = saved;      }    if (next != null)      {        next.apply(stylesheet, mode,                   context, pos, len,                   parent, nextSibling);      }  }