XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (301 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
6.48Mb size Format: txt, pdf, ePub

It's relatively unusual to see variables whose name includes a namespace prefix. It can be useful, though, if you want to write a general-purpose reusable library module in XSLT or XQuery; you can then define global variables to hold constants visible to users of the library, and putting these in a specific namespace will help to ensure that there are no naming conflicts. In fact, XQuery requires that global variables exported from a module are declared in the namespace associated with that module.

Examples

$x
$lowest-common-denominator
$ALPHA
$my-ns-prefix:param1
$ Π
$ (: you can have a comment here :) x

Parenthesized Expressions

A
ParenthesizedExpr
either consists of an expression enclosed in parentheses, or it consists of an empty pair of parentheses, used to represent the empty sequence.

Expression
Syntax
ParenthesizedExpr
(
Expr?
)

When the contained
Expr
is present, parentheses have the same effect in XPath as in most other languages; they change the order of evaluation, so that the enclosed expression is evaluated first, regardless of the normal operator precedence.

Parentheses are sometimes needed around an expression that uses the
,
operator (which denotes list concatenation), to avoid the
,
being interpreted as a separator between the arguments in a function call or the clauses of a
for
expression. For example, to find the maximum of two numbers
$i
and
$j
, you need to write
max(($i, $j))
, to make it clear that the function is being called with one argument (a sequence) and not with two. The
,
operator is described in detail in Chapter 10. Because
,
has the lowest precedence of any operator, it is generally necessary to use parentheses with it. However, if it is used at the top level of an XPath expression, the parentheses are not needed. For example, one can write in XSLT:

Other books

Perfect Plot by Carolyn Keene
Sam's Legacy by Jay Neugeboren
Hot Monogamy by St. Vincent, Lucy
Dead and Gone by Bill Kitson
WolfsMate_JCS by Desconhecido(a)
Invasion USA by William W. Johnstone