Chapter 8. Extending XSLT

To this point, we’ve spent a lot of time learning how to use the built-in features of XSLT and XPath to get things done. We’ve also talked about the somewhat unusual processing model that makes life challenging for programmers from the world of procedural languages (a.k.a. Earth). But what do you do if you still can’t do everything with XSLT and XPath?

In this section, we’ll discuss the XSLT extension mechanism that allows you to add new functions and elements to the language. Unfortunately, Version 1.0 of the XSLT standard doesn’t define all of the details about how these things should work, so there are some inconsistencies between processors. The good news is that if you write an extension function or element that works with your favorite processor, another vendor can’t do something sinister to prevent your functions or elements from working. On the other hand, if you decide to change XSLT processors, you’ll probably have to change your code.

Most examples in this chapter are written for the Xalan processor. We’ll discuss how to write stylesheets that can work with multiple processors, and we’ll briefly look at the differences between the various APIs supported by those processors. In addition, Xalan comes with extensions written in Java, but you can use other languages, as well. We’ll look at extensions written in Jython (formerly JPython), JavaScript, and Jacl.

Extension Elements, Extension Functions, and Fallback Processing

Section 14 ...

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