Chapter 9. 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 chapter, we’ll discuss the XSLT extension mechanism that allows you to add new functions and elements to the language. The XSLT standard doesn’t define all of the details about how these things should work, so there are some differences 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. The less good news is that if you decide to change XSLT processors, you’ll probably have to change your code.

Along the way, we’ll also discuss the EXSLT project, whose goals are to provide a common library of extension functions that work across different XSLT processors.

The examples in this chapter are written for the Java-based Saxon and Xalan processors, and for the .NET framework (using C#). 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, the Xalan-J processor supports Apache’s Bean Scripting Framework ...

Get XSLT, 2nd Edition 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.