[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Managing debug logging in complex transforms: what do people do?


Subject: Re: [xsl] Managing debug logging in complex transforms: what do people do?
From: Eliot Kimber <ekimber@xxxxxxxxxxxx>
Date: Mon, 24 Mar 2014 14:13:33 -0500

I'll take a look at assert. I'm not sure static variables address my
requirements since the emitting of the debug messages may be dynamically
controlled within a given template or function using values that couldn't
be known at compile time (e.g., <xsl:variable name="doDebug" select="@id =
'1234'" as="xs:boolean"/>, the equivalent of a watch statement in a
procedural debugger).

With respect to Brian's post: I'm emitting messages to the console, not to
the result, but I like the idea of preprocessing the XSLT itself to add
the logging details--I'll have to think about that.

Cheers,

E.

On 3/24/14, 1:42 PM, "Michael Kay" <mike@xxxxxxxxxxxx> wrote:


>
>On 24 Mar 2014, at 17:31, Eliot Kimber <ekimber@xxxxxxxxxxxx> wrote:
>
>> For whatever reason I find using interactive debugging unhelpful for
>> debugging XSLT processing (but I couldn't code a line of Java without
>>it).
>
>That's my experience too, I have never been sure why the difference.

I think it may be the nature of the apply-templates process makes "step
into" less obvious or practical than in a procedural language where it's
much clearer where you're going to go when you step. I also find that
often when I do try to "step into" that the transform just completes and I
can't figure out where I should have set a breakpoint or why it didn't
work. With messages you can at least trace exactly what's happening.

>> 
>> Thus I depend very heavily on debug messages in my XSLTs. I used to just
>> emit messages and then comment them out or delete them when I was done,
>> but then I found myself recreating those messages when I had to return
>>to
>> that bit of code.
>> 
>> Then I started using a runtime parameter to turn debugging on or off
>> globally and using IF checks to output my messages. But that results in
>>a
>> lot of messages when you've got a lot of debug messages, most of which
>>are
>> not relevant to your current problem, so back to commenting things out
>>or
>> disabling the IF check (e.g., test="false() and $doDebug").
>> 
>
>There are two things in XSLT 3.0 designed to make this easier:
>xsl:assert, and static variables/parameters
>
>xsl:assert is like xsl:message wrapped in an xsl;If.
>
>Static variables can be used in conjunction with xsl:use-when effectively
>as an "ifdef", that is a compile-time conditional. So rather than
>commenting code out, you tag it with use-when="$DEBUG".
>
>Michael Kay
>Saxonica


Current Thread
Keywords