Chapter 10. Debugging, Validation, and Documentation

Quite often the stylesheets that you write are for simple (and sometimes one-off) projects. You can just run the transform and inspect the results until it works correctly. If you hit a problem, you can inspect the code and fix it. Sometimes, however, the solution to a problem is not obvious.

Any good XSLT development environment will provide useful debugging features to help you locate problems in your code. Typically, you can step through code, set breakpoints, inspect variables, and trace execution. Then, XSLT itself provides inline messaging and error-tracing features.

Until quite recently it was not possible to validate either source or result documents within an XSLT processor. Validation, apart from passing or failing the document concerned, can help you identify stylesheet errors that you might otherwise find difficult to find, or even miss entirely.

Systematic documentation is often delivered only with the largest and most established projects. However, it is very easy to add documentation to a stylesheet and process it using XSLT.

In this chapter you'll do the following:

  • Experiment with the XSLT Debugger in the Oxygen IDE.

  • Write trace text with <xsl:message> and <xsl:comment>.

  • Survey the features of two XPath error-handling functions.

  • Learn to validate both output and input in your stylesheets using the schema-aware version of the Saxon processor.

  • Use XSLTdoc, an open-source package that makes inline documentation a snap.

Debugging ...

Get Beginning XSLT and XPath: Transforming XML Documents and Data 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.