[xsl] Need help sorting groups

Subject: [xsl] Need help sorting groups
From: "Steve Wisniewski stevewiz76@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 Jan 2017 14:24:47 -0000
Hi all,
I have this (dumbed-down) source:
<?xml version="1.0" encoding="UTF-8"?><locations> <location> <city>New
York</city> <class>1</class> <value>1000</value> </location> <location>
<city>New York</city> <class>2</class> <value>2000</value> </location>
<location> <city>New York</city> <class>3</class> <value>8000</value>
</location> <location> <city>New York</city> <class>4</class>
<value>6000</value> </location> <location> <city>New York</city>
<class>5</class> <value>500</value> </location> <location> <city>New
York</city> <class>6</class> <value>2000</value> </location> <location>
<city>New York</city> <class>7</class> <value>3000</value> </location>
<location> <city>New York</city> <class>8</class> <value>2000</value>
</location> <location> <city>New York</city> <class>9</class>
<value>1000</value> </location> <location> <city>New York</city>
<class>10</class> <value>1000</value> </location></locations>

Using this stylesheet:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
 <xsl:output method="xhtml" indent="yes"/>
 <xsl:template match="locations"> <table> <thead> <tr> <th>Range</th>
<th>Total Value</th> </tr> </thead> <tbody> <xsl:for-each-group
select="location[(xs:integer(class) eq 1) or (xs:integer(class) eq 2)]"
group-by="city"> <tr> <td>1-2</td> <td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td> </tr>
</xsl:for-each-group> <xsl:for-each-group select="location[(xs:integer(class)
gt 2) and (xs:integer(class) lt 7)]" group-by="city"> <tr> <td>3-6</td>
<td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td> </tr>
</xsl:for-each-group> <xsl:for-each-group select="location[xs:integer(class)
gt 6]" group-by="city"> <tr> <td>7-10</td> <td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td> </tr>
</xsl:for-each-group> </tbody> </table> </xsl:template>
</xsl:stylesheet>

I generate this output:
<table> <thead> <tr> <th>Range</th> <th>Total Value</th> </tr> </thead>
<tbody> <tr> <td>1-2</td> <td>$3,000</td> </tr> <tr> <td>3-6</td>
<td>$16,500</td> </tr> <tr> <td>7-10</td> <td>$7,000</td> </tr>
</tbody></table>

My question is, how can I sort the groups so that they are sorted in value
order like this:
<table> <thead> <tr> <th>Range</th> <th>Total Value</th> </tr> </thead>
<tbody> <tr>
 <td>3-6</td> <td>$16,500</td> </tr> <tr> <td>7-10</td> <td>$7,000</td> </tr>
<tr> <td>1-2</td> <td>$3,000</td> </tr> </tbody></table>
I understand how to sort within a group but cannot figure out how to solve
this issue.B 
Steve

Current Thread