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
4.17Mb 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

Wishful Thinking by Sandra Sookoo
Mirror, The by Heldt, John A.
Extinct by Charles Wilson
Island-in-Waiting by Anthea Fraser
Over the Edge by Suzanne Brockmann
First Chair by Nikki Hoff
The Dom Project by Heloise Belleau, Solace Ames
Shogun by James Clavell
Loving Me, Trusting You by C. M. Stunich