What Is a Variable?
In XSLT, a variable is used to represent something—perhaps 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 can’t 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 can’t modify them after they’re defined.