Glossary sorting

You can automatically sort your glossaries by setting a stylesheet parameter. Glossary sorting is particularly useful when translating a glossary, because translation in place usually puts entries out of alphabetical order. Rather than rearranging the entries in the source file, you can just specify the sort feature.

You can turn on glossary sorting by setting the stylesheet parameter glossary.sort to 1 (default value is zero). Then each group of glossentry elements is sorted alphabetically on the glossterm element contained within each glossentry. The sort feature works for regular glossaries as well as those generated from a glossary database. The glossary sort feature was added starting with version 1.73 of the stylesheets.

Entries are sorted within each glossdiv, glosslist, or glossary container, whichever is the parent element. There is currently no provision for generating letter titles to divide letter groups. The templates in the glossary.xsl stylesheet module would need to be customized to generate such groupings.

The sort sequence is determined by the current value of the lang attribute (which defaults to en if no lang or xml:lang attribute is present).

The sort attempts to fold together uppercase and lowercase, and accented and unaccented characters, for most Latin alphabet languages. It does that by using the gentext templates named normalize.sort.input and normalize.sort.output, which are defined in each of the locale files that are described in the section “Generated text”. The normalize.sort.input text is a sequence of all the lowercase letters, and they are matched by the sequence of uppercase letters in normalize.sort.output. These are used as arguments in the XSLT translate() function, whose purpose is to substitute one character for another. Each glossary term is converted to uppercase for sorting purposes only, and presented in its original letter case. If the case folding for the language you are processing is not correct (leading to an incorrect sort order), then you can customize those gentext templates for each language.