XSLT

One Minute Review

Positives
  • Excellent coverage of a vast subject
  • Starts from the very first baby steps
  • Takes the user all the way to the Empyrean
Negatives
  • Pretty dense presentation can be hard to take in
  • Puts rather a strain on the shoulders

Buy it now

Ratings and Stats

ISBN:0596527217 Relevance:
5
Publisher:O'Reilly Readability:
4
Overall:
5
Bottom Line:A terrific effort that might not be an "I've never done this before" introduction, but will certainly have a place on your bookshelf if you work with XSLT with any regularity!

Intent and Audience

This book takes on a massive task, covering XSLT 1.0 and 2.0 and (to a lesser but still necessarily significant extent) all the specifications that support them. Naturally, the result, at nearly 1,000 pages, is pretty much as massive as the task. About one-third of the pages constitute introductory and tutorial material; the remainder is reference material in the many appendices.

While technically the book covers things from the ground up, enabling users to use this as a one-stop shop from first "Hello World!" example to mind-boggling expertise, the non-reference material is a bit dense and hard to read. (A proviso, however: XSLT does a lot and covers a lot; to make it a more hand-holding intro might easily have double the book's size.)

This book is of course perfect for those who already have some expertise in XSLT 1.0 and want to familiarize themselves with the many useful changes in XSLT 2.0 and its related specifications. For those just starting out in XSLT, this might well be a terrific second book, the reference you need having gotten a good start elsewhere. For those in between, there's far more here than just reference; give it a try and, really, you'll never be sorry you bought the book. It will grace your bookshelf for many a year to come.

Chapter Highlights

Chapter 1 - Getting Started

Before you can do anything with XSLT, you have to understand the basics of XML. These are briefly mentioned here, as are several of the specifications relevant to and supporting XSLT. Also discussed are installation processes for the XSLT processors discussed and exemplified in the book: for XSLT 1.0 only, Xalan-J, Xalan-C, the Microsoft .NET framework, and the MSXSL processor; for XSLT 2.0, Saxon (especially Saxon-B, which excludes schema support and some performance improvements found in Saxon-SA, the commercial version) and the XSLT engine from Altova's XML Spy. These are released under a variety of licensing terms; links to explore are given below.

Chapter 2 - The Obligatory Hello World Example

From a very simple XML document (courtesy of the XML 1.0 specification, no less!) come several output versions from different stylesheets that demonstrate clearly the separation between content and presentation that XSLT enables.

Chapter 3 - XPath: A Syntax for Describing Needles and Haystacks

A key to XSLT is understanding XPath, the language used to designate items to be worked on in XML source documents. The structure of an XML document as seen by XPath 1.0 is explicated, followed by the changes and additions in the XPath 2.0 specification. Since the changes are very significant between XSLT (and XPath) 1.0 and 2.0, the titles of the sections of the book dealing with 2.0 are prefaced with "[2.0]", which makes it easy to identify which to go to or to skip, depending upon your processor. Datatypes and operators in XPath are covered in some detail, as are the differences between "basic" and "schema-aware" XSLT 2.0 processors.

Chapter 4 - Creating Output

At this point, we begin exploring the most basic of XSLT elements, <xsl:text> and <xsl:value-of>. These elements, formatting elements, and use of <xsl:copy> and <xsl:copy-of> make up the bulk of the coverage, which is clearly aimed at generating text quickly. A section on controlling whitespace concludes this initial discussion.

Chapter 5 - Branching and Control Elements

If only there were never decisions to be made! However, in real life, decisions are always before us: all programming languages have to deal with them and XSLT is no exception. XSLT parameters and variables are presented, as is the use of recursion, something central to XSLT 1.0 development but often obviated by the changes in XSLT and XPath 2.0.

Chapter 6 - Creating Links and Cross-References

A key to information these days is linking it to other information for a variety of reasons (pointing to explanations, to more detail, to fuller treatment, etc.). A datum without a link is a lonely player indeed in the world of Web 2.0. Using the XML ID, IDREF, and IDFREFS datatypes and the XSLT key() and generate-id() functions to provide output with references to other data is covered.

Chapter 7 - Sorting and Grouping Elements

Closely related to linking data is sorting and grouping it; the idea of organizing data is common to both. Sorting and especially grouping are much changed in XSLT 2.0, but coverage of the Muench method for grouping items in XSLT 1.0 is included.

Chapter 8 - Combining Documents

Not only data is related to other data in this world, but documents are frequently related to other documents. XSLT provides the ability to combine documents using the document() function, but this is only the beginning: information may have to be sorted, grouped, or linked across multiple documents. XSLT 2.0 simplifies the process, but the XSLT 1.0 way to accomplish such tasks is also presented.

Chapter 9 - Extending XSLT

Surprisingly, XSLT doesn't allow you to do everything you can conceive of (what language does?). But XSLT defines an extension mechanism for those times when the XSLT specification just doesn't provide what you need. XSLT 2.0 adds the <xsl:function> element, which can simplify this process. Extension examples include using custom collations for text sorting, generating "hidden word" graphics to defeat automatic HTML form parsers, and generating an SVG pie chart to display data. It is possible, using some XSLT processors (Xalan-J is mentioned) to write extensions in scripting languages like Jython, JRuby, Jacl (Java implementations of Python, Ruby, and Tcl, respectively), and JavaScript, among others. Finally, for commonly-used XSLT extensions, the EXSLT project provides functionality that is at least somewhat portable across several processors. The text provides an example interacting with a database using Xalan-J and Saxon; an sample extension using Xalan-J, Saxon, and .NET concludes the main text.

Appendices

References to and overviews of XSLT, XPath, XQuery Functions, XML Schema, XSLT formatting codes, and a guide to migration to XSLT 2.0 make up the appendices. This material is perhaps not meant for reading so much as for reference. As such, however, they are invaluable, and probably constitute the real value of the book.

Relevance of Material

The coverage of the topic is admirably thorough and accurate. The reference appendices are superb, in particular Appendix G, "XSLT 2.0 Migration Guide". A careful perusal of that one will be good input to the decision whether or not you need to upgrade your XSLT processor and stylesheets to make use of the new technologies.

The glossary at the end of the text is a must-have for those who only touch upon XSLT from time to time and need a quick refresher on what's what. The various specifications often use similar words with slightly (but importantly) different meanings; this sorts most of them out. Like much of the rest of the book, it details new terms in XSLT 2.0 with a "[2.0]" annotation, so they stand out and can be easily consulted.

Resources

The book web site: http://www.oreilly.com/catalog/9780596527211

The XSLT 1.0 specification: http://www.w3.org/TR/xslt

The XSLT 2.0 specification: http://www.w3.org/TR/xslt20/

The Saxon web site: http://saxon.sourceforge.net/

The Saxonica web site (for information about Saxonica-SA): http://www.saxonica.com/

The Altova XML Spy XSLT processor: http://www.altova.com/altovaxml.html

The Xalan-J web site: http://xml.apache.org/xalan-j/

The Xalan-C web site: http://sml.apache.org/xalan-c/

The .NET Framework Developer Center: http://msdn.microsoft.com/en-us/netframework/default.aspx

The MSXML XSLT processor: http://msdn.microsoft.com/XML/XMLDownloads/default.aspx

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)