--- /home/cpdev/src/classpath/gnu/xml/transform/ApplyTemplatesNode.java	2005-07-10 05:32:33.000000000 +0000
+++ gnu/xml/transform/ApplyTemplatesNode.java	2005-06-30 05:34:19.000000000 +0000
@@ -41,7 +41,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
-import java.util.LinkedList;
 import java.util.List;
 import javax.xml.namespace.QName;
 import javax.xml.transform.TransformerException;
@@ -64,9 +63,11 @@
   final List withParams;
   final boolean isDefault;
 
-  ApplyTemplatesNode(Expr select, QName mode,
+  ApplyTemplatesNode(TemplateNode children, TemplateNode next,
+                     Expr select, QName mode,
                      List sortKeys, List withParams, boolean isDefault)
   {
+    super(children, next);
     this.select = select;
     this.mode = mode;
     this.sortKeys = sortKeys;
@@ -88,18 +89,12 @@
       {
         withParams2.add(((WithParam) withParams.get(i)).clone(stylesheet));
       }
-    TemplateNode ret = new ApplyTemplatesNode(select.clone(stylesheet),
-                                              mode, sortKeys2, withParams2,
-                                              isDefault);
-    if (children != null)
-      {
-        ret.children = children.clone(stylesheet);
-      }
-    if (next != null)
-      {
-        ret.next = next.clone(stylesheet);
-      }
-    return ret;
+    return new ApplyTemplatesNode((children == null) ? null :
+                                  children.clone(stylesheet),
+                                  (next == null) ? null :
+                                  next.clone(stylesheet),
+                                  select.clone(stylesheet),
+                                  mode, sortKeys2, withParams2, isDefault);
   }
 
   void doApply(Stylesheet stylesheet, QName mode,
@@ -112,26 +107,14 @@
       {
         if (withParams != null)
           {
-            // compute the parameter values
-            LinkedList values = new LinkedList();
+            // push the parameter context
+            stylesheet.bindings.push(false);
+            // set the parameters
             for (Iterator i = withParams.iterator(); i.hasNext(); )
               {
                 WithParam p = (WithParam) i.next();
                 Object value = p.getValue(stylesheet, mode, context, pos, len);
-                Object[] pair = new Object[2];
-                pair[0] = p.name;
-                pair[1] = value;
-                values.add(pair);
-              }
-            // push the parameter context
-            stylesheet.bindings.push(Bindings.WITH_PARAM);
-            // set the parameters
-            for (Iterator i = values.iterator(); i.hasNext(); )
-              {
-                Object[] pair = (Object[]) i.next();
-                QName name = (QName) pair[0];
-                Object value = pair[1];
-                stylesheet.bindings.set(name, value, Bindings.WITH_PARAM);
+                stylesheet.bindings.set(p.name, value, false);
               }
           }
         Collection ns = (Collection) ret;
@@ -159,6 +142,10 @@
                                                     false);
             if (t != null)
               {
+                if (stylesheet.debug)
+                  {
+                    System.err.println("Applying " + t);
+                  }
                 stylesheet.current = node;
                 t.apply(stylesheet, effectiveMode, node, i + 1, l,
                         parent, nextSibling);
@@ -167,7 +154,7 @@
         if (withParams != null)
           {
             // pop the variable context
-            stylesheet.bindings.pop(Bindings.WITH_PARAM);
+            stylesheet.bindings.pop(false);
           }
       }
     // apply-templates doesn't have processable children
@@ -178,35 +165,6 @@
                    parent, nextSibling);
       }
   }
-
-  public boolean references(QName var)
-  {
-    if (select != null && select.references(var))
-      {
-        return true;
-      }
-    if (withParams != null)
-      {
-        for (Iterator i = withParams.iterator(); i.hasNext(); )
-          {
-            if (((WithParam) i.next()).references(var))
-              {
-                return true;
-              }
-          }
-      }
-    if (sortKeys != null)
-      {
-        for (Iterator i = sortKeys.iterator(); i.hasNext(); )
-          {
-            if (((SortKey) i.next()).references(var))
-              {
-                return true;
-              }
-          }
-      }
-    return super.references(var);
-  }
   
   public String toString()
   {
