Chapter 6. Exploiting XSLT 2.0

If the only new thing we have to offer is an improved version of the past, then today can only be inferior to yesterday. Hypnotized by images of the past, we risk losing all capacity for creative change.

Robert Hewison

Introduction

XSLT 2.0 has numerous additions and enhancements that make doing hard things in XSLT easier. This chapter will help the XSLT 1.0 veteran make the transition to 2.0 and also help the XSLT newbie understand how to better approach stylesheet design in 2.0.

XSLT 2.0 derives much of its improved functionality from XPath 2.0, so if you have skipped Chapter 1, then you should consider reading that first.

As with most progress in software technology, version 2.0 is an improved version of the old rather than a complete rethinking of stylesheet design. It also falls short in some features that could have made it a much better language (e.g., introspection and direct support for higher-order functions). However, XSLT 2.0 goes a long way toward elevating the drudgery of developing complex stylesheet logic. The key features in 2.0 are XPath functions, grouping, enhanced modes, cleaner idioms for reusable code, a richer type system, and enhanced support for text processing. All of these features are used to improve the 2.0 recipes that appear in this edition, but this chapter provides a one-stop reference for the new features themselves.

6.1. Convert Simple Named Templates to XSLT Functions

Problem

XSLT 1.0 did not support writing XPath functions ...

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