Chapter 8 - Variables in XSLT: A Breed Apart | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
A variable is a handy little gadget used in nearly every programming language. Not to be left out, XSLT has variables as well, but theyre quite different from those you find in Visual Basic, JavaScript, C++, or Java. They are truly their own breed. In XSLT, a variable is used to represent somethingperhaps a chunk of text, a numeric value, boilerplate HyperText Markup Language (HTML), or even a collection of XML tree nodes. But, in a manner quite different from its cousins in other languages, an XSLT variable cant change its value after you declare it. Actually, if you want to draw any comparisons, an XSLT variable is perhaps closest to a constant in a traditional programming language. XSLT is quite powerful by using template rules and XPath expressions to transform XML into pretty much any output that you can imagine. Variables help to augment these tools by enabling you to make what techies call run-time changes (or for the rest of us, changes that happen at the time the XSLT is processed ). Run-time changes enable your transformation to adapt to a condition that exists at the time of execution rather than having all the canned answers prepared beforehand. Admittedly, XSLT variables are limited in their ability to do many things on the fly because you cant modify them after theyre defined.
|