Subject: RE: [xsl] 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 |
> 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] qualitative decline of xs, DPawson | Thread | RE: [xsl] debugging techniques [was, Eric van der Vlist |
Re: [xsl] Getting my text children, David Carlisle | Date | RE: [xsl] Getting my text children, Michael Kay |
Month |