The variables that exist at run-time do not necessarily correspond exactly to those defined in your source code. In this case there is only one reference to $title, and it isn't in a loop, so Saxon will have inlined its definition. That is, it will have rewritten your code as
 
  <xsl:template match="/">
    <Order> 
      <Output>
        <xsl:value-of select="/Order/Title"/>
      </Output>
    </Order>
  </xsl:template>

There are also cases where the Saxon optimizer will add variables, or convert local variables to global variables.
 
You can use the "-explain" option to see what rewrites Saxon has performed.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Marc Pellmann
Sent: 23 April 2008 09:51
To: Mailing list for the SAXON XSLT and XQuery processor
Subject: [saxon] Local variables in TraceListener

Hi!

I want to get informations about the used variables in an xlst script and use an own
TraceListener. I tried this:

public void enter(InstructionInfo instruction, XPathContext context) {
        StackFrame stackFrame = context.getStackFrame();
        List variables = stackFrame.getStackFrameMap().getVariableMap();
          ...

because StackFrame says "This class represents a stack frame holding details of
the variables used in a function or in an XSLT template."

But for the following script "variables" is always empty and I never get an instruction
that shows the variable!?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> 
  <xsl:output method="xml" encoding="ISO-8859-1"/> 
  <xsl:template match="/">
    <Order>
      <xsl:variable name="title" select="/Order/Title"/> 
      <Output>
        <xsl:value-of select="$title"/>
      </Output>
    </Order>
  </xsl:template>
</xsl:stylesheet>

best regards, marc.