How are index entries sorted in alphabetical order in DITA?
Sorting index entries in alphabetical order is a common requirement in DITA documentation to enhance the usability of indexes. DITA provides mechanisms to achieve this alphabetical sorting of index entries, ensuring that readers can easily locate the information they are looking for.
Using Sort As Attribute
One way to sort index entries alphabetically is by using the “sort-as” attribute in your DITA XML. This attribute allows you to specify a term by which the index entry should be sorted, even if the actual index term might include characters that would lead to a different sorting order. Here’s an example of how to use the “sort-as” attribute:
<index>
<indexterm>
<primary>Apple</primary>
<sort-as>Macintosh</sort-as>
</indexterm>
<indexterm>
<primary>Banana</primary>
</indexterm>
<indexterm>
<primary>Cherry</primary>
</indexterm>
</index>
In this example, “Macintosh” is specified as the term to sort by for the index entry “Apple,” ensuring that it appears in the correct alphabetical order in the index.
Automatic Alphabetical Sorting
Sometimes, your publishing tool or DITA processing engine may offer options for automatic alphabetical sorting of index entries. By configuring your processing settings, you can instruct the tool to sort the index entries for you, simplifying the process and reducing the need for manual “sort-as” attributes.
Example:
Here’s an example of using the “sort-as” attribute to achieve alphabetical sorting of index entries in DITA documentation:
<index>
<indexterm>
<primary>Apple</primary>
<sort-as>Macintosh</sort-as>
</indexterm>
<indexterm>
<primary>Banana</primary>
</indexterm>
<indexterm>
<primary>Cherry</primary>
</indexterm>
</index>
By using the “sort-as” attribute, you can ensure that “Apple” is sorted under “Macintosh” in the index, providing a more intuitive alphabetical order for readers.