Search This Blog

Wednesday, November 28, 2007

Use Custom Collations in XSLT 2.0

One emphasis of XSLT 2.0 is better support for internationalization,
especially sorting and comparing text. This seemingly simple task is
quite complicated in some languages; for example, accented characters
can be considered the same or different depending on context. Are A+acute,
A+grave, and A the same letter? Sometimes the answer needs to be yes,
despite the fact that they are three different code points. The simple
string comparison functions found in most languages, including XSLT 1.0,
aren't up to the task. This article demonstrates how to write a custom
collation function using XSLT extensions and invoke it from an XSLT 2.0
stylesheet with the open-source Saxon processor. To use a custom
collation with Saxon, you specify the name of the Java class that
implements the collation function. XSLT 2.0 has a number of functions
and elements that allow you to specify a collation. A collation is the
heart of any sorting algorithm. A collation function compares two items
and returns one of three values. If the first item appears before the
second, the function returns a value less than zero. If the two items
are equal, the function returns zero. Finally, as you might expect, if
the first item appears after the second, the return value is greater
than zero... More Information See also the Saxon web site: Click Here

No comments: