Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If you omitted the
as=“xs:string”
from the
(120.00)
; but for all practical purposes the value could still be used as if it were a string. One difference is that you won't get such good type checking: For example, if you try to use the variable
$credit-in-paren
as defined above in a context where a number is required, this will be reported as an error, quite possibly at compile time. But if you leave off the
as
attribute, you will probably not get an error at all, just a wrong answer: The system will treat the value of the variable as
NaN
(not a number).
Changing the Context Item
If you want to use
For example, suppose you have written a template that returns the depth of the current node (the number of ancestors it has). The template has been given a unique name and an identical mode name:
Now, suppose you want to obtain the depth of a node other than the context node—let's say the depth of the next node in document order, which need not be on the same level as the context node. You can call this template in either of two ways.
Using
or using
In both cases the variable
$next-depth
will, on return, hold a value, which is the depth in the tree of the node following the context node. If the context item is not a node, a runtime error will occur. Because the
as
attribute, the result is of type
xs:integer
. Without the
as
attribute, the result would be a temporary document containing a single text node, whose value is the string representation of this integer. For details, see
Recursion: Processing a List of Values
Named templates are sometimes used to process a list of values. As XSLT has no updateable variables like a conventional programming language, it also has no conventional
for
or
while
loop, because these constructs can only terminate if there is a control variable whose value is changing.
In XSLT 2.0 most processing of sequences can be done iteratively, using the XSLT
for
expression; for example: