Automating the Insertion of Debug Output

Problem

You want to transform your stylesheet into another stylesheet that is instrumented with debug traces.

Solution

Oliver Becker developed a handy stylesheet transformation that takes any input stylesheet and produces an output stylesheet with trace instrumentation:

<!-- Trace utility, modifies a stylesheet to produce trace messages Version 0.2 GPL (c) Oliver Becker, 2002-02-13 obecker@informatik.hu-berlin.de --> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:trace="http://www.obqo.de/XSL/Trace" xmlns:alias="http://www.w3.org/TransformAlias" exclude-result-prefixes="alias"> <xsl:namespace-alias stylesheet-prefix="alias" result-prefix="xsl" /> <!-- <xsl:output indent="yes" /> --> <!-- XSLT root element --> <xsl:template match="xsl:stylesheet | xsl:transform"> <xsl:copy> <!-- We need the trace namespace for names and modes --> <xsl:copy-of select="document('')/*/namespace::trace" /> <!-- dito: perhaps a namespace was used only as attribute value --> <xsl:copy-of select="namespace::*|@*" /> <xsl:apply-templates /> <!-- append utility templates --> <xsl:copy-of select="document('')/*/xsl:template [@mode='trace:getCurrent' or @name='trace:getPath']" /> <!-- compute the lowest priority and add a default template with a lower priority for element nodes --> <xsl:variable name="priority" select="xsl:template/@priority [not(. &gt; current( )/xsl:template/@priority)]" /> <xsl:variable name="newpri"> <xsl:choose> ...

Get XSLT Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.