TechBookReport logo



Keywords: XML, XSLT, XPath, data transformations

Title: XSLT Cookbook

Author: Sal Mangano

Publisher: O'Reilly

ISBN: 0596003722

Media: Book

Level: Intermediate/Advanced

Verdict: A great learning resource and reference

Getting started with XSLT is pretty straightforward if you've got a simple task to complete. Pick any of the tutorials off the web, grab a copy of Saxon (or whatever) cut and paste a simple template and off you go. Once you've had a taste of what you can achieve you'll be wanting more, no doubt about it. However, digging deeper means really having to get to grips with the functional programming style of XSLT and this is where things can get tricky. At this point it pays to look at something like Michael Fitzgerald's 'Learning XSLT', which is a great introduction but even this only goes so far. Thankfully Sal Mangano's 'XSLT Cookbook' is a great way into more advanced topics.

Cookbooks are a great idea, whether it's for honing your skills in the food department or improving your coding skills. Of course in both cases you need to know your way around the kitchen first. In this case Mangano assumes a basic working knowledge of XSLT, as such this makes a great follow-on to an introductory text like 'Learning XSLT' or even Erik Ray's 'Learning XML'. There is no introductory chapter or refresher material in this book, it goes straight into the first recipes immediately after the preface.

The book is broken up into 14 chapters, which start from relatively straightforward topics such as string manipulation and maths and then moves on to look at things like transforming XML to text, XML to HTML, XML to XML and much more. More esoteric topics include XML to SVG transformations (including generating diagrams and charts direct from XML data), code generation, vertical applications (including Visio and Excel) and extending XSLT using Java and JavaScript. Finally, the book also includes a chapter on testing and debugging, a topic that rarely seems to get tackled.

Each chapter is organised into sections, and these are geared around problems to be solved (for example merging documents with identical schema, exporting XML to delimited data and so on). Each section starts with a statement of the problem to be solved which is followed with one or more solutions. These are illustrated with example data and (annotated) stylesheets. The solution is then wrapped up with a detailed discussion, including gotchas and alternatives, and finished with any relevant cross-references. The text is generally straightforward and to the point, it avoids the twin vices of condescension or lame humour.

As well as the wide range of recipes that are included in the book, and which make for great jumping off points for your own code, the book is useful in a number of ways. Firstly there is the sheer range and inventiveness of the code that is listed. The idea that XSLT is an extremely powerful and flexible programming language, (it is after all Turing complete), doesn't really sink in until you see templates that do date arithmetic or fill in for some of the missing math functions that aren't natively available. Secondly, many of the recipes in the book are built in modular fashion, reusing simpler templates and putting things together to create complex transformations. It's a great example to follow, and along with the many idioms that are included in the recipes, it adds significantly to the value to be gained from the book.

It's worth noting that the book is geared firmly around XSLT 1.0, there is little specific coverage of XSLT 2.0.


Hit the 'back' key in your browser to return to subject index page

Return to home page