Order records in XML emitter. Closes #3337.

This is difficult to test since the database might choose to give you
the records in order anyway. Removing the `sort`s from the actual
values should at least catch it sometimes.