[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Need help sorting groups

Subject: Need help sorting groups
From: "Steve Wisniewski stevewiz76@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 Jan 2017 14:24:47 -0000
 Need help sorting groups
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.