O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required