People in cafeJean Paoli
speakingAmsterdam rooftopsXTech delegats
XTech 2007: “The Ubiquitous Web”15-18 May 2007, Paris, France
Your account


(?)
XTech 2007 news

Subscribe to receive news about XTech

Partners





Sponsors


Organized by

Conference Chair

Co-Hosts

Event software by Expectnation
Add to your personal schedule

My stylesheet runs, but...

Tony Graham (Menteith Consulting Ltd)
Core technology Concorde-Invalides
Chair: Jeni Tennison (The Stationery Office)

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.

My stylesheet runs, but it’s too slow

Profilers are in wide use for conventional programming, and several XSLT and XSL profilers are available. However, it is a truism of XSLT programming that different XSLT processors have their own strengths and weaknesses, so if you are profiling your stylesheet, it is important to profile it running on the same XSLT processor as you will use in production.

Some XSLT processors, such as Saxon and libXSLT, have their own profiling mechanisms, and several XSLT editors or IDEs, such as <oXygen/>, Stylus Studio, and XML Spy, provide built-in profilers what work with a number of different XSLT processors.

Profiling XSLT is not an exact science since:

  • The execution time for a template includes the execution times of all of the templates that it calls; the processor and IDE vendors do their best to separate the two when reporting timing.
  • Results depend on the state of the machine; so running the stylesheet multiple times in succession generally means the later runs are faster than the earlier as the program and its libraries are already in memory.
  • Only xsltproc provides a command-line switch for running the transformation time multiple times to counteract irregularities in the timing of a single run.
  • The time taken by a particular template may depend as much on the current node list as on the structure of the template.

The presentation will describe the features and applicability of the different XSLT and XSL profilers available as well as a few hints and tips about how to get the best out of your profiler: such as what to do when the profiler reports that your hottest hotspot is a literal result element instead of the complicated XPath selector that you expected.

My stylesheet runs, but how do I know it’s correct

Unit tests – tests written from the perspective of the programmer – came to prominence with the rise in popularity of the Extreme Programming (XP) methodology in the late 1990s. Programmers have always recognised that they should write tests for their code, but that hasn’t always meant that they do. Writing tests before writing the code is central to XP, so the publicity about XP brought unit testing to the attention of many programmers, irrespective of whether they adopted all, some, or none of the XP methodology. The practise can be separated from the rest of the XP bag of tricks and referred to as Test-Driven Development (TDD).

Unit testing is most commonly associated with the Java programming language since XP’s creators also wrote the JUnit unit testing framework and since Ant, the ubiquitous Java-based build tool, makes it easy to run JUnit tests and generate HTML reports of the results. Unit testing tools are available for a wide variety of programming languages, including XSLT, but current awareness of XSL and XSLT unit testing tools is limited.

Your choice of XSLT unit testing framework depends less on your XSLT processor than it does on your XSLT version and your testing approach. There is already at least one unit testing framework specific to XSLT 2.0 (which will limit your choice of XSLT processor), but otherwise your choice depends on whether you want to work purely in XSLT, within Ant, with Ant and JUnit, with just JUnit. Again, your choice will depend on what other tools you are using.

XSLT unit testing frameworks include:

  • http://xsltunit.org/
  • http://juxy.tigris.org/
  • http://www.jenitennison.com/xslt/utilities/unit-testing/
  • http://xmlunit.sourceforge.net/
  • http://utf-x.sourceforge.net/
  • http://www.fgeorges.org/xslt/xslt-unit/

My stylesheet runs, but how do I know I’m testing enough

That is the role of coverage tools. I’m still looking for a coverage tool, and have plans to write my own.

My stylesheet runs, but how can I check my FO after its formatted

This area is less well developed. The xmlroff XSL formatter has a framework for rasterising PDF or PostScript output and comparing formatted pages against a reference, and the FOP XSL formatter has a framework for comparing the XML renditions of its area tree against a reference.

Tony Graham

Menteith Consulting Ltd

Tony Graham is an independent consultant specialising in XSL, XSLT, and XML. He has been working with markup since 1991, with XML since 1996, and with XSL/XSLT since 1998.

Tony is an invited expert on the W3C XSL FO subgroup and a previous member of the W3C XML Protocol WG. He is the author of Unicode: A Primer and the developer of the xmlroff XSL Formatter. He is a member of the XML Guild.

Tony is interested in applying the tools for ensuring software quality – unit testing, code coverage, profiling, and other tools – to XML and XSL/XSLT processing.