code: protected ElemVariable getPrevVariableElem(ElemTemplateElement elem)
    {
    	// This could be somewhat optimized.  since getPreviousSiblingElem is a  
    	// fairly expensive operation.
    	while(null != (elem = getPrevElementWithinContext(elem)))
    	{
    		int type = elem.getXSLToken();
    			
    		if((Constants.ELEMNAME_VARIABLE == type) ||
    		   (Constants.ELEMNAME_PARAMVARIABLE == type))
    		{
    			return (ElemVariable)elem;
    		}
    	}
    	return null;
    }
docs: Find the previous occurance of a xsl:variable.  Stop
  the search when a xsl:for-each, xsl:template, or xsl:stylesheet is
  encountered.
  
  @param elem Should be non-null template element.
  @return The first previous occurance of an xsl:variable or xsl:param,
  or null if none is found.