garyp       01/07/11 02:54:27

  Modified:    java/src/org/apache/xalan/templates ElemVariable.java
                        StylesheetRoot.java
               java/src/org/apache/xpath VariableStack.java
               java/src/org/apache/xpath/operations Variable.java
  Log:
  Resolve bugzilla 2355 
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2355>.  Added code to 
populate m_index for global variables and parameters.  If the backward search 
for templates reaches the top level, use the list of composed top-level 
variables and parameters from StylesheetRoot.
  
  Revision  Changes    Path
  1.13      +21 -6     
xml-xalan/java/src/org/apache/xalan/templates/ElemVariable.java
  
  Index: ElemVariable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/ElemVariable.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ElemVariable.java 2001/06/19 21:33:48     1.12
  +++ ElemVariable.java 2001/07/11 09:54:21     1.13
  @@ -87,23 +87,38 @@
    */
   public class ElemVariable extends ElemTemplateElement
   {
  +
     /**
  +   * Constructor ElemVariable
  +   *
  +   */
  +  public ElemVariable(){}
  +
  +  /**
      * This is the index into the stack frame.  If the index is above the 
      * global area, it will have to be offset at execution time.
      */
     protected int m_index;
     
  -  // Get the relative index of this variable.
  -  public int getIndex()
  +  /**
  +   * Sets the relative position of this variable within the stack frame (if 
local)
  +   * or the global area (if global).  Note that this should be called only 
for
  +   * global variables since the local position is computed in the compose() 
method.
  +   */
  +  public void setIndex(int index)
     {
  -    return m_index;
  +    m_index = index;
     }
   
     /**
  -   * Constructor ElemVariable
  -   *
  +   * If this element is not at the top-level, get the relative position of 
the
  +   * variable into the stack frame.  If this variable is at the top-level, 
get
  +   * the relative position within the global area.
      */
  -  public ElemVariable(){}
  +  public int getIndex()
  +  {
  +    return m_index;
  +  }
   
     /**
      * The value of the "select" attribute.
  
  
  
  1.44      +1 -0      
xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java
  
  Index: StylesheetRoot.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/templates/StylesheetRoot.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- StylesheetRoot.java       2001/07/10 07:49:07     1.43
  +++ StylesheetRoot.java       2001/07/11 09:54:22     1.44
  @@ -752,6 +752,7 @@
       if (getVariableOrParamComposed(elemVar.getName()) == null)
       {
         elemVar.setIsTopLevel(true);        // Mark as a top-level variable or 
param
  +      elemVar.setIndex(m_variables.size());
         m_variables.addElement(elemVar);
       }
     }
  
  
  
  1.32      +15 -22    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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- VariableStack.java        2001/07/10 07:49:10     1.31
  +++ VariableStack.java        2001/07/11 09:54:24     1.32
  @@ -426,18 +426,18 @@
       // Get the current ElemTemplateElement, which must be pushed in as the 
       // prefix resolver, and then walk backwards in document order, searching 
       // for an xsl:param element or xsl:variable element that matches our 
  -    // qname.  For this to work really correctly, the stylesheet element 
  -    // should be immediatly resolve to the root stylesheet, and the 
operation 
  -    // performed on it's list of global variables.  But that will have to 
wait 
  -    // for another day, or someone else can do it, or I will come up with a 
  -    // better solution to this whole damned hack.
  -    if (prefixResolver
  -            instanceof org.apache.xalan.templates.ElemTemplateElement)
  +    // qname.  If we reach the top level, use the StylesheetRoot's composed
  +    // list of top level variables and parameters.
  +
  +    if (prefixResolver instanceof 
org.apache.xalan.templates.ElemTemplateElement)
       {
  +      
  +      org.apache.xalan.templates.ElemVariable vvar;
  +
         org.apache.xalan.templates.ElemTemplateElement prev =
           (org.apache.xalan.templates.ElemTemplateElement) prefixResolver;
   
  -      while (null != prev)
  +      while ( !(prev.getParentNode() instanceof 
org.apache.xalan.templates.Stylesheet) )
         {
           org.apache.xalan.templates.ElemTemplateElement savedprev = prev;
   
  @@ -445,28 +445,21 @@
           {
             if (prev instanceof org.apache.xalan.templates.ElemVariable)
             {
  -            org.apache.xalan.templates.ElemVariable vvar =
  -              (org.apache.xalan.templates.ElemVariable) prev;
  +            vvar = (org.apache.xalan.templates.ElemVariable) prev;
   
               if (vvar.getName().equals(qname))
  -            {
  -              int index = vvar.getIndex();
  -              boolean isGlobal = vvar.getIsTopLevel();
  -
  -              if(isGlobal)
  -                return getGlobalVariable(xctxt, index);
  -              else
  -                return getLocalVariable(xctxt, index);
  -            }
  +              return getLocalVariable(xctxt, vvar.getIndex());
             }
           }
  -
           prev = savedprev.getParentElem();
         }
  +
  +      vvar = prev.getStylesheetRoot().getVariableOrParamComposed(qname);
  +      if (null != vvar)
  +        return getGlobalVariable(xctxt, vvar.getIndex());
       }
   
  -    throw new javax.xml.transform.TransformerException(
  -      "Variable not resolavable: " + qname);
  +    throw new javax.xml.transform.TransformerException("Variable not 
resolvable: " + qname);
     }
   }  // end VariableStack
   
  
  
  
  1.12      +25 -14    
xml-xalan/java/src/org/apache/xpath/operations/Variable.java
  
  Index: Variable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/operations/Variable.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Variable.java     2001/06/19 21:52:09     1.11
  +++ Variable.java     2001/07/11 09:54:26     1.12
  @@ -189,30 +189,31 @@
           // Get the current ElemTemplateElement, which must be pushed in as 
the 
           // prefix resolver, and then walk backwards in document order, 
searching 
           // for an xsl:param element or xsl:variable element that matches our 
  -        // qname.  For this to work really correctly, the stylesheet element 
  -        // should be immediatly resolve to the root stylesheet, and the 
operation 
  -        // performed on it's list of global variables.  But that will have 
to wait 
  -        // for another day, or someone else can do it, or I will come up 
with a 
  -        // better solution to this whole damned hack.
  -        if(prefixResolver instanceof 
org.apache.xalan.templates.ElemTemplateElement)
  +        // qname.  If we reach the top level, use the StylesheetRoot's 
composed
  +        // list of top level variables and parameters.
  +
  +        if (prefixResolver instanceof 
org.apache.xalan.templates.ElemTemplateElement)
           {
  +
  +          org.apache.xalan.templates.ElemVariable vvar;
  +
             org.apache.xalan.templates.ElemTemplateElement prev = 
  -            (org.apache.xalan.templates.ElemTemplateElement)prefixResolver;
  +            (org.apache.xalan.templates.ElemTemplateElement) prefixResolver;
               
  -          while(null != prev)
  +          while ( !(prev.getParentNode() instanceof 
org.apache.xalan.templates.Stylesheet) )
             {
               org.apache.xalan.templates.ElemTemplateElement savedprev = prev;
  -            while(null != (prev = prev.getPreviousSiblingElem()))
  +
  +            while (null != (prev = prev.getPreviousSiblingElem()))
               {
                 if(prev instanceof org.apache.xalan.templates.ElemVariable)
                 {
  -                org.apache.xalan.templates.ElemVariable vvar = 
  -                  (org.apache.xalan.templates.ElemVariable)prev;
  +                vvar = (org.apache.xalan.templates.ElemVariable) prev;
                   
  -                if(vvar.getName().equals(m_qname))
  +                if (vvar.getName().equals(m_qname))
                   {
                     m_index = vvar.getIndex();
  -                  m_isGlobal = vvar.getIsTopLevel();
  +                  m_isGlobal = false;
                     m_fixUpWasCalled = true;
                     return execute(xctxt);
                   }
  @@ -220,9 +221,19 @@
               }
               prev = savedprev.getParentElem();
             }
  +
  +          vvar = 
prev.getStylesheetRoot().getVariableOrParamComposed(m_qname);
  +          if (null != vvar)
  +          {
  +            m_index = vvar.getIndex();
  +            m_isGlobal = true;
  +            m_fixUpWasCalled = true;
  +            return execute(xctxt);
  +          }
  +
           }
         }
  -      throw new javax.xml.transform.TransformerException("Variable not 
resolavable: "+m_qname);
  +      throw new javax.xml.transform.TransformerException("Variable not 
resolvable: "+m_qname);
       }
     }
   }
  
  
  

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

Reply via email to