Constants

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. In XPath 2.0, string delimiters can be doubled within the string to represent the delimiter itself: for example <xsl:value-of select='"He said, ""Go!"""'/>

Numeric constants 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 a 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.

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 require 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").

XPath 2.0 allows the argument to a constructor to contain whitespace, as determined by the whitespace facet for the target data type.