Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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
 
Old March 2nd, 2008, 06:57 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default 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


 
Old March 3rd, 2008, 05:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>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
 
Old March 3rd, 2008, 08:11 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

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



 
Old March 3rd, 2008, 08:19 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old March 3rd, 2008, 08:45 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

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,


 
Old March 3rd, 2008, 09:04 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

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
 
Old March 3rd, 2008, 09:13 AM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Great - thank you!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Best Practices Class gxp Spring 0 August 21st, 2008 06:02 PM
View layer best practices danielpilon C# 0 May 8th, 2008 07:41 AM
ObjectDataSource Best Practices? TKelley4591 BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 0 July 20th, 2007 02:39 PM
XSLT Best Practices tripecac XSLT 1 May 4th, 2007 06:02 PM
Design Practices rfurman1161 Access 3 March 24th, 2006 09:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.