Page 1 of 1
					
				Debugging XSL functions (non-Java)
				Posted: Mon Dec 15, 2008 7:38 pm
				by DAndres109
				I'm just getting my feet wet with XSL 2.0 and am currently learning about creating custom functions within an XSL stylesheet.  These functions are as simple as the following:
Code: Select all
<xsl:function name="test:get-length">
   <xsl:param name="input" as="xs:string" />
   <xsl:sequence select="string-length($input)" />
</xsl:function>
I've tried debugging usages of this type of function using both Saxon and SaxonSA in Oxygen 10, but I am only able to see that a call has been made.  I cannot step into the function call itself or inspect the parameters passed to it.
Is there a way to step into custom functions such as these?
 
			
					
				Re: Debugging XSL functions (non-Java)
				Posted: Tue Dec 16, 2008 12:11 pm
				by Dan
				Saxon is optimizing the XSLT execution by using code rewrite. This very clear when having a variable that gets assigned multiple times:
Code: Select all
<xsl:variable name="v" select="'abc'"/>
<xsl:variable name="v" select="string-join($v,'def')"/>
<xsl:variable name="v" select="string-length($v)"/>
After compilation, the processor will discard the intermediate steps and will evaluate directly:
Code: Select all
<xsl:variable name="v" select="string-length(string-join('abc','def'))"/>
The same is holding for the xsl:sequence constructions.
In your case, to force the XSLT processor step into the function, you should insert an evaluation that cannot be rewriten by the processor, for instance an xsl:message :
Code: Select all
<xsl:function name="test:get-length">
   <xsl:param name="input" as="xs:string" />
   <xsl:message select="$input"/>
   <xsl:sequence select="string-length($input)" />
</xsl:function>
 
			
					
				Re: Debugging XSL functions (non-Java)
				Posted: Tue Dec 16, 2008 2:59 pm
				by DAndres109
				This does allow me to step into the xsl:message declaration, but the next step move will take me out of the function.
From a Saxon perspective, is there any way to disable this code optimization for debug purposes?
			 
			
					
				Re: Debugging XSL functions (non-Java)
				Posted: Tue Dec 16, 2008 4:35 pm
				by Dan
				We had a few discussions with dr. Michael Kay regarding a debugging mode of Saxon in which the optimisations would be disabled, but unfortunately all this remained at the intention level.
I think all the people interested in this Saxon new feature should contact Michael and ask him about it: 
http://www.saxonica.com/