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

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

, because in this case there is a primary difference.

The
strength
of a collation determines what kind of differences it takes into account. For comparing equality between strings, it is often appropriate to use a collation with weak strength; for example, a collation with primary strength will treat
attache
as equal to
attaché
. (In French this is not necessarily the right thing to do, as these two words have completely different meanings, but it would be appropriate if there is a high possibility that accents have been omitted from one of the strings.) When sorting, however, it is almost always best to use a collation with high strength, which will take secondary, and if necessary tertiary, differences into account when there are no primary differences.

Sometimes it is better, rather than defining two separate sort key components, to concatenate the sort key values into a single sort key component. For example, if you define a single sort key component as:


this might give better results than:



This is because in the second case above, a tertiary difference in the last name is considered more significant than a primary difference in the first name: so
MacMillan Tricia
will be sorted before
Macmillan Harold
. When the sort key values are concatenated, the difference between
MacMillan
and
Macmillan
is only taken into account when the first names are the same. (To reproduce the order of entries found in a UK phone book, you would need a collation that interleaves the Macdonalds and McDonalds, but this is beyond the scope of the UCA.)

Dynamic Sort Keys

The
select
attribute contains an expression which is evaluated for each item in the initial sequence, with that item as the context item, to give the value that determines the item's position in the sequence. There's no direct way of specifying that you want to use different sort keys on different occasions. I've seen people try to write things like:



    

           

hoping that if
$sort-key
is set to
TITLE
, the elements will be sorted by title, and that if
$sort-key
is set to
AUTHOR
, they will be sorted by author. This doesn't work: the variable
$sort-key
has the same value for every

element, so the books will always be output in unsorted order. In this case, where the sort key is always a child element of the elements being sorted, you can achieve the required effect by writing:

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

Other books

Finders and Keepers by Catrin Collier
Steamy Southern Nights by Warren, Nancy
Wake Unto Me by Lisa Cach
Hong Kong Heat by Raven McAllan
Not Your Average Happy Ending by Chantele Sedgwick
Indiscretions by Elizabeth Adler
Judgment by Denise Hall