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

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

If the
use
expression returns nodes, the nodes will be atomized. The resulting values can be of any atomic type, or a mixture of different atomic types. When you use the
key()
function to search for a node, the value you supply is compared with the indexed values according to the rules of the XPath
eq
operator. Generally, this means you must supply a value of the right type: for example, if the indexed value is an integer, and you search for a string, then you won't find anything. However, the usual type conversions occur automatically: numbers such as integers and doubles can be compared with each other, and
xs:untypedAtomic
values can be compared to strings.

In backward-compatibility mode (when the stylesheet specifies
version=“1.0”
), both the values returned by the
use
expression and the values supplied to the
key()
function are converted to strings and are compared as strings. This means you won't get a match between different representations of the same number, such as
1
and
001
, but you will get a match between the number
1
and the string
“1”
.

The
collation
attribute identifies a collation that will be used when the key value is a string. If no collation is specified, a default collation is used (this will usually be the Unicode Codepoint Collation, described below). Collations are discussed under

on page 459. You need to decide whether you want to use a weak collation, in which strings such as
ASCII
and
ascii
are considered equivalent, or a strong collation, in which they are considered to be different. You might also need to consider what language should be used to define the matching rules. One of the options, which might be the best choice when you are comparing strings such as part numbers, is to use the Unicode Codepoint Collation, which considers two strings to be equal only if they use the same Unicode characters, as identified by their codepoint values. You can request this using the collation URI:

Other books

Nothing But Fear by Knud Romer
Darkest by Ashe Barker
New Species 07 Tiger by Laurann Dohner
By Reason of Insanity by Shane Stevens
Pursued by Cynthia Dane
Cancer-Fighting Cookbook by Carolyn F. Katzin