Debugging XSL functions (non-Java)

Having trouble installing Oxygen? Got a bug to report? Post it all here.
DAndres109
Posts: 4
Joined: Mon Dec 15, 2008 7:28 pm

Debugging XSL functions (non-Java)

Post 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?
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Debugging XSL functions (non-Java)

Post 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>
DAndres109
Posts: 4
Joined: Mon Dec 15, 2008 7:28 pm

Re: Debugging XSL functions (non-Java)

Post 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?
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Debugging XSL functions (non-Java)

Post 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/
Post Reply