O'Reilly logo

Effective XML: 50 Specific Ways to Improve Your XML by Elliotte Rusty Harold

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required