Item 39. Parameterize XSLT Stylesheets

There's an old programmer's adage that the only numbers in programs should be 0, 1, and infinity. Everything else should be a named constant. The same can be said for styles in XSLT stylesheets. Sooner or later somebody is going to want to customize anything they can customize. To enable this, use named variables (an XSLT variable is much like a C++ const) instead of hard-coding styles like 12pt or bold.

The key to this is top-level xsl:variable and xsl:param elements. These are direct children of the root xsl:stylesheet element. Each such element has a name attribute that sets the name of the variable (or parameter) and a select attribute that sets the value of the variable (or parameter) using an XPath ...

Get Effective XML: 50 Specific Ways to Improve Your XML 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.