Implementing collations in Java

If you want to use your own URIs to define collations, there are two ways of doing this:

  • You can use the Saxon configuration file to define collations: see The collations element.

  • You can register a collation with the Saxon Configuration using the method s9api method Processor.declareCollation() or the underlying method Configuration.registerCollation().

In either case, the collation is supplied in the form of an implementation of the interface net.sf.saxon.lib.StringCollator. You must supply methods compareStrings() and comparesEqual() for comparing strings for ordering or equality, and a method getCollationKey() which returns a collation key for any string. If you want your collation to be used in calls of fn:contains(), fn:starts-with(), fn:ends-with(), fn:substring-before(), or fn:substring-after(), then it must also implement the interface net.sf.saxon.lib.SubstringMatcher.