Research into custom sorting, to implement Nx alphabetical order
Nx has a specific sort order for its alphabet, which doesn't follow the instant results you would get from a normal alphabetical sort. For instance, the glottal stop comes at the beginning, and the reverse glottal at the end; a normal default XSLT alpha sort, as well as the Unicode codepoint sort, place the glottal after the y.
In order to get sorting to work the way we need it to, we'll have to define a custom sort collation. Since we're using XSLT 2.0 and Saxon 8, we can do that following the instructions on the Saxon site for implementing a collation sequence. What we have to do is to write a Java class which implements the java.util.Comparator
interface. This IBM page has more details of the interface.
Because Java isn't my thing, I'm now looking around for a simple example I can modify. So far I've only found this, which is too basic to be much use. This shows a simple example of a case-insensitive comparator:
public class CaseInsensitiveComparator implements java.util.Comparator { public int compare(Object o1, Object o2) { String s1 = o1.toString().toUpperCase(); String s2 = o2.toString().toUpperCase(); return s1.compareTo(s2); } }
but it shells out to the default string comparator to do the real work. What we need is an example of an efficient way to compare individual characters. One possibility is to have a string comparator which also embodies a character comparator; the character comparator would tell you which of two characters sorts first, and the string comparator would call that for each character in the strings until it found an inequality. I have no idea if I'm on the right track here, though, so I'll keep researching for the moment. This is something that will be called frequently, so it has to be pretty fast.