Literals
String literals are written as "London" or
'Paris'. In each case you can use the opposite kind of quotation mark
within the string: 'He said "Boo"', or "That's rubbish". In a
stylesheet XPath expressions always appear within XML attributes, so it is usual to use
one kind of delimiter for the attribute and the other kind for the literal. Anything
else can be written using XML character entities. String delimiters can be doubled
within the string to represent the delimiter itself: for example <xsl:value-of
select='"He said, ""Go!"""'/>
Numeric literals follow the Java rules for decimal literals: for
example, 12 or 3.05; a negative number can be written as (say)
-93.7, though technically the minus sign is not part of the literal.
(Also, note that you may need a space before the minus sign to avoid it being treated as
a hyphen within a preceding name). The numeric literal is taken as a double precision
floating point number if it uses scientific notation (e.g. 1.0e7), as fixed
point decimal if it includes a full stop, or as an integer otherwise. Decimal values
(and integers) in Saxon have unlimited precision and range (they use the Java classes
BigInteger and BigDecimal internally). Note that a value
such as 3.5 was handled as a double-precision floating point number in
XPath 1.0, but as a decimal number in XPath 2.0: this may affect the precision of
arithmetic results.
Since XPath 4.0, numeric integer literals can be written in hex
(0xFFFF0000) or binary (0b101010), and underscores can be
used as separators (1_000_000). (Implemented from Saxon 12.1.)
There are no boolean constants as such: instead use the function calls true() and false().
Constants of other data types can be written using constructors, which look like
function calls but generally take a string literal as their argument. For example,
xs:float("10.7") produces a single-precision floating point number.
Saxon implements constructors for all of the built-in data types defined in XML Schema
Part 2.
An example for date and dateTime values: you can write
constants for these data types as xs:date("2002-04-30") or
xs:dateTime("1966-07-31T15:00:00Z").
The argument to a constructor can contain leading or trailing whitespace, as determined by the whitespace facet for the target data type.
QName literals are introduced in XPath 4.0, as an
alternative to using the xs:QName constructor function. A QName literal
is written as the character # followed by an EQName: for example,
#xml:space is the QName with local part space and namespace
URI http://www.w3.org/XML/1998/namespace. (Implemented from Saxon 13.)