garyp       01/03/09 10:07:20

  Modified:    java/src/org/apache/xalan/transformer TransformerImpl.java
               java/src/org/apache/xpath VariableStack.java
  Log:
  Parameters set with setParameter were available to stylesheet as variable 
references ($myParam) even though there was no xsl:param element to receive it.
  
  Revision  Changes    Path
  1.87      +22 -4     
xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java
  
  Index: TransformerImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/transformer/TransformerImpl.java,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- TransformerImpl.java      2001/03/06 05:50:24     1.86
  +++ TransformerImpl.java      2001/03/09 18:07:19     1.87
  @@ -1354,7 +1354,7 @@
       QName qname = new QName(namespace, name);
       XObject xobject = XObject.create(value);
   
  -    varstack.pushOrReplaceVariable(qname, xobject);
  +    varstack.pushOrReplaceParameter(qname, xobject);
     }
     
     Vector m_userParams;
  @@ -1580,8 +1580,19 @@
     }  // end pushParams method
   
     /**
  -   * Internal -- push the global variables onto
  -   * the context's variable stack.
  +   * Internal -- push the global variables from the Stylesheet onto
  +   * the context's runtime variable stack.
  +   * <p>If we encounter a variable
  +   * that is already defined in the variable stack, we ignore it.  This
  +   * is because the second variable definition will be at a lower import
  +   * precedence.  Presumably, global variables at the same import precedence
  +   * with the same name will have been caught during the recompose process.
  +   * <p>However, if we encounter a parameter that is already defined in the
  +   * variable stack, we need to see if this is a parameter whose value was
  +   * supplied by a setParameter call.  If so, we need to "receive" the one
  +   * already in the stack, ignoring this one.  If it is just an earlier
  +   * xsl:param or xsl:variable definition, we ignore it using the same
  +   * reasoning as explained above for the variable.
      *
      * @param contextNode The root of the source tree, can't be null.
      *
  @@ -1606,8 +1617,15 @@
       {
         ElemVariable v = (ElemVariable) vars.elementAt(i);
   
  -      if (vs.variableIsDeclared(v.getName()))
  +      Arg previouslyDeclared = vs.getDeclaredVariable(v.getName());
  +      if (null != previouslyDeclared)
  +      {
  +        if ( (v instanceof ElemParam) && 
previouslyDeclared.isFromWithParam() )
  +        {
  +          previouslyDeclared.setIsVisible(true);
  +        }
           continue;
  +      }
   
         // XObject xobj = v.getValue(this, contextNode);
         XObject xobj = new XUnresolvedVariable(v, contextNode, 
  
  
  
  1.27      +10 -10    xml-xalan/java/src/org/apache/xpath/VariableStack.java
  
  Index: VariableStack.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/VariableStack.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- VariableStack.java        2001/03/07 04:27:18     1.26
  +++ VariableStack.java        2001/03/09 18:07:20     1.27
  @@ -259,7 +259,7 @@
   
     
     /**
  -   * Push an argument onto the stack, or replace it 
  +   * Push a parameter onto the stack, or replace it 
      * if it already exists.  Don't forget
      * to call startContext before pushing a series of
      * arguments for a given macro call.
  @@ -267,7 +267,7 @@
      * @param qname The qualified name of the variable.
      * @param val The wrapped value of the variable.
      */
  -  public void pushOrReplaceVariable(QName qname, XObject xval)
  +  public void pushOrReplaceParameter(QName qname, XObject xval)
     {
       Stack frame = getCurrentFrame();
       if(frame == m_emptyStackFrame)
  @@ -345,16 +345,16 @@
   
     
     /**
  -   * Tell if a variable or parameter is already declared, 
  +   * Returns a variable or parameter that is already declared, 
      * either in the current context or in the global space.
      *
      * @param qname The qualified name of the variable.
      *
  -   * @return true if the variable is already declared.
  +   * @return the Arg if the variable is already declared, otherwise 
<code>null</code>.
      *
      * @throws TransformerException
      */
  -  public boolean variableIsDeclared(QName qname) throws TransformerException
  +  public Arg getDeclaredVariable(QName qname) throws TransformerException
     {
   
       Stack frame = getCurrentFrame();
  @@ -365,13 +365,13 @@
   
         if (((Arg) obj).getQName().equals(qname))
         {
  -        return true;
  +        return (Arg) obj;
         }
       }
             
       Stack gframe = (Stack)this.elementAt(0);
       if(gframe == frame)
  -      return false;
  +      return null;
       
       for (int i = (gframe.size() - 1); i >= 0; i--)
       {
  @@ -379,11 +379,11 @@
   
         if (((Arg) obj).getQName().equals(qname))
         {
  -        return true;
  +        return (Arg) obj;
         }
       }
   
  -    return false;
  +    return null;
     }
   
   
  @@ -454,7 +454,7 @@
       {
         Arg arg = (Arg)gframe.elementAt(i);
   
  -      if (arg.getQName().equals(name))
  +      if (arg.getQName().equals(name) && arg.isVisible())
         {
           XObject val = arg.getVal();
           if(val.getType() == XObject.CLASS_UNRESOLVEDVARIABLE)
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to