Hi All,

I think I may have found a big of a bug and was wondering if someone could 
comment.  I'm creating my own custom extension element for logging (mainly as a 
way to learn more about extension elements).  The code snippet in question 
looks something like this:

<xsl:template match="/">
   <xsl:variable name="testvar" select="'blah'"/>
   <myext:log logLevel="debug" message="${testvar}"/>
</xsl:template>

In my extension code, after I get the attribute from message I try to look it 
up using:

XPathContext xCtx = context.getTransformer().getXPathContext();
VariableStack varStack = xCtx.getVarStack();
XObject value = (XObject)varStack.getVariableOrParam(xCtx, variableName);

But I get a TransformerException that says testvar is unresolvable.

So I put some logging code in to ensure that testvar actually existed:

                        if(log.isDebugEnabled()){
                            log.debug("Searching for variable or parameter " + 
key);
                            log.debug("Number of variables available: " + 
varStack.size());                            
                            for(int i=0; i < varStack.size();i++){
                                XObject obj = varStack.elementAt(i);            
                    
                                log.debug("Variable " + i + " = " + 
obj.toString() + " of type " + obj.getTypeString());                            
    
                                log.debug("System Id: " + obj.getSystemId());
                                log.debug("Public Id: " + obj.getPublicId());
                            }                            
                        }

And it logged out fine, it was of type XString....so the variable actually 
exists.

I traced the problem to line 519 of VariableStack, in the method 
getVariableOrParam.  The statement:

if (!(prev instanceof org.apache.xalan.templates.Stylesheet)){...}

The if statement evaluates to false as the variable prev is an instance of 
org.apache.xalan.templates.StylesheetRoot so it doesn't use that block of code 
to search, but the following piece of code:

vvar = prev.getStylesheetRoot().getVariableOrParamComposed(qname);

returns null

I know the variable exists because of the previous logging code, but the method 
getVariableOrParam can't find it?  I am removing the ${} before I do the search 
and just passing new QName(null, null, "testvar") into the getVariableOrParam 
method...the ${} is just there so I can use 
org.apache.commons.lang.text.StrSubstitutor to do a template like substitution.

Any assistence anyone could give would be greatly appreciated.  Am I looking up 
a variable incorrectly or is it a bug.  If it's a bug, I'm happy to fix it with 
some direction.

I'm using Xalan-j 2.7.1

Cheers
Adam





       
---------------------------------
Get the name you always wanted with the new y7mail email address.

Reply via email to