Modify to call get_sorted_query always in generate_xml.
Merge branch 'fix-query' into develop