In this example, there is only one reference to the variable, so the optimizer will have inlined it: the variable will not actually exist at run-time.
You could try setting opt:0 to disable optimization (this won't actually disable all optimizations, but I think it should work for this one).
The -explain flag should help you understand what the optimized code looks like.
The other thing to be aware of is that (regardless of optimization) variables may be lazily evaluated - the variable is not evaluated when it is declared, but when it is first referenced.


Michael Kay

From: Alexandre Brillant []
Sent: 12 February 2010 13:56
Subject: [saxon] Problem for tracing variables and parameters in saxon 9


I try to trace the variables and the parameters when running and the bound values.

Here my XSLT sample, the variable name should be traced

<xsl:stylesheet version="2.0" 
exclude-result-prefixes="xs xdt err fn">

<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">

<xsl:template match="person">
<xsl:variable name="name" select="name/family"/>
<h1><xsl:value-of select="concat($name,'test')"/></h1>


In my code, I used the TraceListener

public void enter(InstructionInfo arg0, XPathContext xc ) {

  StackFrame stackFrame = xc.getStackFrame(); List variables = stackFrame.getStackFrameMap().getVariableMap();   
System.out.println( variables );


The problem is that the variables list is always empty ? How can I get the list of variables and parameters ?

Thank you for your help, 

Best regards,