Use custom collations in XSLT 2.0

摘自: IBM developerWorks Worldwide  被阅读次数: 352


yangyi 于 2009-05-08 23:06:30 提供


Level: Advanced

Doug Tidwell (dtidwell@us.ibm.com), Technology Evangelist, IBM 

27 Nov 2007

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 Á , À 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 and invoke it from an XSLT 2.0 stylesheet.

Custom collations

In this article you'll use some of the new features of XSLT 2.0 and XPath 2.0. 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.

......

Please access the below link to view the full content.

Original link: http://www.ibm.com/developerwork...