Bug 5982 and 6022. The variable stack was not being cleared accross transforms so that when the transformer is reused, we were using nodesets from the previous transform which were using a different DTM. Note that we want keep any variables that have been set externally by the user (using Transformer.setParameter()).


git-svn-id: https://svn.apache.org/repos/asf/xalan/java/trunk@336000 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/org/apache/xalan/transformer/TransformerImpl.java b/src/org/apache/xalan/transformer/TransformerImpl.java
index 2cbdc3d..de2e394 100644
--- a/src/org/apache/xalan/transformer/TransformerImpl.java
+++ b/src/org/apache/xalan/transformer/TransformerImpl.java
@@ -467,7 +467,10 @@
       m_stackGuard = new StackGuard();
 
       m_xcontext.reset();
+      m_xcontext.getVarStack().clearLocalSlots(0, m_xcontext.getVarStack().size());
+      resetUserParameters();
       m_xcontext.getVarStack().reset();
+      
 
       int n = m_currentTemplateElements.length;
       for (int i = 0; i < n; i++) 
@@ -1511,6 +1514,43 @@
       return null;
     }
   }
+  
+  /**
+   * Reset parameters that the user specified for the transformation.
+   * Called during transformer.reset() after we have cleared the 
+   * variable stack. We need to make sure that user params are
+   * reset so that the transformer object can be reused. 
+   */
+  private void resetUserParameters()
+  {
+
+    try
+    {
+      
+      if (null == m_userParams)
+        return;
+
+      int n = m_userParams.size();
+      for (int i = n - 1; i >= 0; i--)
+      {
+        Arg arg = (Arg) m_userParams.elementAt(i);
+        QName name = arg.getQName();
+        // The first string might be the namespace, or it might be 
+        // the local name, if the namespace is null.
+        String s1 = name.getNamespace();
+        String s2 = name.getLocalPart();
+
+        setParameter(s2, s1, arg.getVal().object());
+        
+      }
+      
+    }
+    catch (java.util.NoSuchElementException nsee)
+    {
+      // Should throw some sort of an error.
+      
+    }
+  }
 
   /**
    * Set a bag of parameters for the transformation. Note that