Chapter 17. Stylesheet Design Patterns
This chapter looks at four common design patterns for XSLT stylesheets.
The concept of design patterns was introduced by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides in their classic book Design Patterns: Elements of Reusable Object-Oriented Software (Addison-Wesley Publishing, 1995). Their idea was that there was a repertoire of techniques that were useful again and again. They presented 23 different design patterns for object-oriented programming, claiming not that this was a complete list but that the vast majority of programs written by experienced designers fell into one or more of these patterns.
For XSLT stylesheets, the vast majority of stylesheets I have seen fall into one of four design patterns. These are as follows:
Fill-in-the-blanks stylesheets
Navigational stylesheets
Rule-based stylesheets
Computational stylesheets
Again, this doesn't mean that these are the only ways you can write stylesheets, nor does it mean that any stylesheet you write must follow one of these four patterns to the exclusion of the other three. It just means that a great many stylesheets actually written by experienced people follow one of these four patterns, and if you become familiar with these patterns, you will have a good repertoire of techniques that you can apply to solving any given problem.
I describe the first three design patterns rather briefly, because they are not really very difficult. The fourth, the computational design pattern, ...
Get XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th 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.