Testing XSLT

Tony Graham
Menteith Consulting

Presented at XML 2007 in Boston, USA, on 5 December 2007. Download slides

Creating a working stylesheet may seem like an end in itself, but once it’s written you may want it to run faster or you may not be sure that the output is correct (And if you are sure, how sure are you?).

Profilers, unit test frameworks, and other tools of conventional programming are similarly available for XSLT but are not widely used. This presentation surveys the available tools for ensuring the quality of your XSLT.

There is no one-size-fits-all solution when looking for tools. For example, if you are using Saxon and Ant, then you are looking for a different set of tools than if you are using libXSLT and Makefiles.

This training is for people familiar with XSLT – either XSLT 1.0 or XSLT 2.0 – who want to improve the reliability and accuracy of their stylesheets.

Overview of XSLT testing tools

Overview of the categories of XSLT and XSL FO testing tools.

XSLT profilers

More detailed look at XSLT profilers and some of the potential for inaccuracy in the reported results.

XSLT unit testing frameworks

When to do unit tests and how effective they are.

A look at the available XSLT unit testing frameworks and their differing technologies and differing approaches.

Black box testing

What tests can you infer from the input and desired output?

White box testing

Writing tests when you can see the code being tested.

The roles of both “clean” tests and “dirty” tests, where the template is supposed to throw an error.

xsl:message and unit testing

Problems with assertions about xsl:message with pure XSLT frameworks.

Errors not caught by unit testing

Review of the types of errors – misleading comments, off-by-one errors, empty #PCDATA, etc. – that are not caught by unit testing.

XSLV static validation tool

A different approach to testing transformations.

XSL FO testing frameworks

xmlroff and FOP testing tools

Concluding remarks

Review of the tool types and their strengths and weaknesses.