SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
| Introduction
| Constants
» | Variable References
| Function Calls
| Axis steps
| Parentheses and operator precedence
| Filter expressions
| Path expressions
| Cast as, Treat as
| Set difference and intersection
| Union
| Arithmetic expressions
| Range expressions
| Comparisons
| Instance of and Castable as
| Conditional Expressions
| Quantified Expressions
| For Expressions
| Boolean expressions: AND and OR
| Sequence expressions
Function Library
Standards Conformance

# Variable References

The value of a variable (local or global variable, local or global parameter) may be referred to using the construct `$name`, where name is the variable name.

The variable is always bound at the textual place where the expression containing it appears; for example a variable used within an `xsl:attribute-set` must be in scope at the point where the attribute-set is defined, not the point where it is used.

A variable may be declared to be of a particular type, for example it may be constrained to be an integer, or a sequence of strings, or an attribute node. In a schema-aware environment, this may also be a reference to a user-defined type in a schema. If there is no type declared for the variable, it may take a value of any data type, and in general it is not possible to determine its data type statically.

It is an error to refer to a variable that has not been declared.

Starting with XPath 2.0, variables (known as range variables) may be declared within an XPath expression, not only using `xsl:variable` elements in an XSLT stylesheet. The expressions that declare variables are the `for`, `some`, and `every` expressions. In XQuery, variables can also be declared in a `let` or `typeswitch` expression, as well as in the signature of a user-written function.

Next