O'Reilly logo

XML Companion, The, Third Edition by Neil Bradley

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

Variables and named templates

A stylesheet often contains a number of templates that produce identical or very similar output. XSLT includes some mechanisms for avoiding such redundancy.

Variables

A 'variable' is a container of information that has a name. Whenever the variable is referenced in the stylesheet, the reference is replaced by the value of the variable.

Variables are declared using the Variable element. The name of the variable is given in the Name attribute, and the value of the variable may be the content of the element. The following example creates a variable called 'Colour', and gives it the value 'red':

<variable name="Colour">red</variable>

Alternatively, the value can be generated from an expression using a Select attribute. ...

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