My recollection is that you can only sort by one key, so you have two options:
create a formula field on the transaction line that combines the elements you want to sort by, and concatenates them together in the sort order you want. I have done this and it works well. you then just sort by the formula column.
alternatively, you might be able to iterate through the list in Freemarker, adding a key to each item. Then sort by the newly added key. I think this will work in theory, but have not tried it. The item list may or may not be editable