[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: debugging techniques [was:qualitative decline of x

Subject: RE: debugging techniques [was:qualitative decline of xsl-list questions]
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 4 Dec 2002 10:23:54 -0000
xsl debug output
> If people would like to recount their debugging experiences 
> and methods,
> I'll collate them for the faq?
> 

Here's a selection, of varying degrees of obviousness.

General-purpose:

  Add <xsl:message> to output progress messages


  Add <xsl:comment> to put messages into the result tree indicating
where output nodes came from


  Use <xsl:comment><xsl:value-of
select="system-property('xsl:vendor')"/></xsl:comment> so you are in no
doubt about which XSLT processor you are using


  To output the values of variables, using attribute value templates is
quicker than using xsl:value-of, e.g. write <debug x="{$x}" y="{$y}"/>


  If you want to leave debug lines in the stylesheet that can be
switched on and off at will, make them into extension elements:

  <xsl:stylesheet xmlns:debug="debug.uri"
    extension-element-prefixes="debug">
  ...

      <debug:debug x="{$x}" y="{$y}"><xsl:fallback/></debug:debug>

  The <debug:debug> element will be ignored, but values will be output
if "debug" is removed from the "extension-element-prefixes" attribute.


  To see what's in a temporary tree (or result tree fragment), copy it
to the output:

  <debug tree="$x">
    <xsl:copy-of select="$x"/>
  </debug>


  To add tracing to all template rules, add a debug module:

  <xsl:import href="real-stylesheet.xsl"/>
  <xsl:template match="*">
    <xsl:message>Processing <xsl:value-of
select="name()"/></xsl:message>
    <xsl:apply-imports/>
    <xsl:message>Finished processing <xsl:value-of
select="name()"/></xsl:message>
  </xsl:template>

  (You can also use xsl:comment instead of xsl:message)


  To deal with character-encoding problems: use a hex editor!


  If the source (or result) XML is badly laid out and difficult to
understand, run it through an indentation transform:

  <xsl:strip-space elements="*"/>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <xsl:copy-of select="."/>
  </xsl:template>  


  If you don't understand the error messages from your XSLT processor
(or if you are beginning to suspect that it has a bug), run the
transformation through another XSLT processor to see if it sheds any
light on the matter.


Saxon-specific:

  Use -T on the command line to switch on tracing

  Use saxon:path() to output an XPath expression that identifies the
context node

  Use saxon:line-number() to output the line number of the context node
in the source file (having switched on numbering using -l on the command
line)

  In 7.x only: add type declarations on variables and parameters, e.g.
  <xsl:param name="x" as="xs:integer"/> to trap type errors.


MSXML3-specific:

  Get your transformation working in standalone mode first, before you
integrate it into the browser. Write the version used in the browser as
a customisation layer (using xsl:import) of the standalone version, and
when debugging is necessary, use the standalone version. Try to avoid
debugging in the browser.



Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.