XML technologies / XSLT / XSLT Cookbook / XSLT: extending and embedding
Extending and embedding XSLT
(Excerpt from “XSLT Kochbuch” by Sal Mangano)
“I think everyone should have a great Wonderbra. You can enhance them in so many ways; everyone does it.”
Christina Aguilera
Introduction
Truly ambitious programmers are never satisfied with what they are given and obsess over improving what they have. I say ambitious rather than great because greatness includes knowing when to work within a system and when to extend it. This chapter nonetheless focuses on extending the system: both XSLT functionality best implemented in another language, and other languages needing to use XSLT.
Extending XSLT is by definition work at the specification’s edges. Extensions reduce stylesheet portability, a definite risk whether using extensions built into your XSLT processor or implementing your own. This remains true even for extensions written in a language as portable as Java. Some XSLT processors are not written in Java and are unlikely ever to support Java extensions. Even targeting only Java-based processors can cause problems, since XSLT 1.0 did not fully standardize extensions. Version 1.1 improved this, but is no longer an official release and is unsupported by many processors. Surprisingly, XSLT 2.0 took a step back from 1.1 by leaving extension-function binding undefined.
EXSLT.org is a portal whose supporters develop standards for XSLT programmers implementing common extensions. In Strings and Numbers and calculations, EXSLT was mentioned for mathematical and date extensions. EXSLT.org also organizes other categories, some touched on in this chapter. Visit it before implementing your own extension: someone may already have developed one, or at least considered how it should work.
In contrast to extending XSLT, embedding XSLT means running transformations from another language without running the processor in a separate forked process. Below, you will see how to access XSLT from Java and Perl programs.
While writing this chapter, it became clear that extending and embedding could fill a whole book, especially across different implementations, extension languages and interesting examples. To keep this chapter manageable, I compromised by switching between Xalan-Java 2 and Saxon, focusing mainly on Java and JavaScript. The chapter also discusses MSXML.
To avoid repetition, this section explains how to use extensions in Saxon, Xalan-Java 2 and MSXML.
Copyright © 2006 O'Reilly Verlag GmbH & Co. KG
You may print the online version for your private use.
Otherwise, this chapter from “XSLT Kochbuch” is subject to the same conditions as the bound edition. The work, including all its parts, is protected by copyright. All rights reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
O'Reilly Verlag GmbH & Co. KG, Balthasarstraße 81, 50670 Köln, kommentar(at)oreilly.de