 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 2nd, 2008, 06:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Debugging - best practices
Hi,
I recently started working on some stylesheets that are very large and complicated. I've implemented some templates to help with debugging. The following will tell me which node I am processing.
Code:
<xsl:template name="getDebug">
<xsl:call-template name="debug">
<xsl:with-param name="mynode">
<xsl:value-of select="node()"/>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="debug">
<xsl:param name="mynode"/>
<xsl:if test="$debug = 'true'">
<xsl:message>
<xsl:text>Processing: </xsl:text>
<xsl:value-of select="name()"/>
</xsl:message>
</xsl:if>
</xsl:template>
to call the template:
Code:
<xsl:call-template name="getDebug"/>
This works great for matching a template node (<xsl:template match="foo">) but not if I am in named template (<xsl:template name="myFoo"/>). Is there a way to get the name of the named template for debugging?
Thanks,
Bones
|
|

March 3rd, 2008, 05:46 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
>Is there a way to get the name of the named template for debugging?
If there is, then it depends entirely on what product you are using, which you haven't mentioned.
You might find it easier to use debugging tools that already exist - for example the debuggers in Stylus Studio or Oxygen, or the -T trace output available from Saxon.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 3rd, 2008, 08:11 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Hi Michael,
I am using FOP 0.94 (command line for XSL-FO development and FOP API for deployment).
The use of Stylus Studio, Oxygen or xmlSpy is not an option for deployment.
I have built a java GUI to do PDF production with the FOP processor. I have added a checkbox to the GUI which has an option for debugging (e.g. $debug).
I can use the Saxon API for XML to XSL-FO and use -t. I was just wondering if there was an easier or better way to debug.
Thanks for the help
|
|

March 3rd, 2008, 08:19 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
The most effective single thing you can do to help debugging is to add type declarations ("as") attributes to your variables and parameters. That will tend to catch your errors earlier (i.e. closer to the incorrect code), often at compile time. If you can make the stylesheet schema-aware and use schema-specific types, so much the better.
Beyond that, I really can't suggest anything much better than inserting xsl:message at appropriate points. (Although people sometimes forget that inserting xsl:comment can be equally effective). The Saxon -T option can be useful, but the output is very voluminous.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 3rd, 2008, 08:45 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Thank you Michael,
"The most effective single thing you can do to help debugging is to add type declarations ("as") attributes to your variables and parameters" -
Can you provide an example?
Thanks,
|
|

March 3rd, 2008, 09:04 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
You might find this article helpful:
http://www.stylusstudio.com/schema_aware.html
However, you can still get benefits without going all the way to schema-awareness, just by declaring types. For example, instead of <xsl:param name="n"/>, write <xsl:param name="n" as="xs:integer"/>, and the system will give you an error if the template or function is called supplying, say, a string.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

March 3rd, 2008, 09:13 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Great - thank you!
|
|
 |