Are These Things Really Variables?
Although these XSLT variables are called variables, they’re not variables in the traditional sense of procedural programming languages such as C++ or Java. Remember that earlier we said one goal behind the design of the stylesheet language is to avoid side effects in execution? Well, one of the most common side effects used in most procedural languages is changing the value of a variable. If we write our stylesheet so that the results depend on the varying values of different variables, the stylesheet engine would be forced to evaluate the templates in a certain order.
XSLT variables are more like variables in the traditional
mathematical sense. In mathematics, we can define a function called
square( that
returns the value of a number (represented by x)) multiplied by
itself. In other words, xsquare(2.5)
returns 6.25. In this context, we
understand that can be any
number; we also understand that the xsquare function can’t change the value of
.x
It takes a while to get used to this concept, but you’ll get there. Trust me on this.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access