SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
XML Schema Processing
The XPath API
Standards Conformance
Extensibility
| Introduction
| Writing extension functions
| Converting Arguments to Extension Functions
| Converting the Result of an Extension Function
| Writing extension instructions
| Writing input filters
| Writing output filters
| Implementing a collating sequence
» | Localizing numbers and dates
| Adding an output encoding
| Writing a URI Resolver for Input Files
| Writing a URI Resolver for Output Files
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
XSLT Patterns

# Localizing numbers and dates

It is possible to define a localized numbering sequence for use by `xsl:number` and `format-date()`. This sequence will be used when you specify a language in the `lang` attribute of the `xsl:number` element, or in the third argument of the functions `format-date()`, `format-time()`, and `format-dateTime()`. The feature is primarily intended to provide language-dependent numbers and dates, but in fact it can be used to provide arbitrary numbering sequences.

To implement a numberer for language X, you need to define a class `net.sf.saxon.number.Numberer_X`, for example `net.sf.saxon.sort.Numberer_xfootnote`. This must implement the interface `Numberer`. A `Numberer` is supplied for `lang="de"` (German) as a specimen, and you can use this as a prototype to write your own. A numbering sequence is also supplied for `lang="en"`, and this is used by default if no other can be loaded.

Normally your localization class will extend the class `Numberer_en` so that you can reuse functionality like roman numerals which do not need to be localized. If you only need to override some methods and not others, you can do so: you will get the English representation of those components you have not localized.

You can override any of the non-private methods in the base class, but the most useful ones to implement are the following:

Method | Effect
ordinalSuffix | Supplies a suffix to be appended to a number to create the ordinal form, for example "1" becomes "1st" in English
toWords | Displays a number in words, in title case: for example "53" becomes "Fifty Three" in English
toOrdinalWords | Displays an ordinal number in words, in title case: for example "53" becomes "Fifty Third" in English
monthName | Displays the name of a month, optionally abbreviated
dayName | Displays the name of a day of the week, optionally abbreviated

Note that any hyphens in the language name are ignored in forming the class name, but case is significant. For example if you specify `lang="en-GB"`, the Numberer must be named `net.sf.saxon.number.Numberer_enGB`.

If you write a comprehensive Numberer for a particular language, please submit it, and I will be happy to include it in future versions of the product as an open-source component.

Next