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

Re: Need help sorting groups

Subject: Re: Need help sorting groups
From: "Steve Wisniewski stevewiz76@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 9 Jan 2017 14:40:13 -0000
Re:  Need help sorting groups
Thanks Martin!

      From: "Martin Honnen martin.honnen@xxxxxx"
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
 Sent: Monday, January 9, 2017 9:37 AM
 Subject: Re:  Need help sorting groups

On 09.01.2017 15:25, Steve Wisniewski stevewiz76@xxxxxxxxx wrote:

> 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.


you can store the result in a variable and then sort it

B  B  B  B  B  B  B  <xsl:variable name="rows" as="element(tr)*">
B  B  B B B  B B B  B B B  <xsl:for-each-group
select="location[(xs:integer(class) eq 1) or
(xs:integer(class) eq 2)]" group-by="city">
B B B  B B B  B B B  B B B  B B B  <tr>
B B B  B B B  B B B  B B B  B B B  B B B  <td>1-2</td>
B B B  B B B  B B B  B B B  B B B  B B B  <td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td>
B B B  B B B  B B B  B B B  B B B  </tr>
B B B  B B B  B B B  B B B  </xsl:for-each-group>
B B B  B B B  B B B  B B B  <xsl:for-each-group
select="location[(xs:integer(class) gt 2) and
(xs:integer(class) lt 7)]" group-by="city">
B B B  B B B  B B B  B B B  B B B  <tr>
B B B  B B B  B B B  B B B  B B B  B B B  <td>3-6</td>
B B B  B B B  B B B  B B B  B B B  B B B  <td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td>
B B B  B B B  B B B  B B B  B B B  </tr>
B B B  B B B  B B B  B B B  </xsl:for-each-group>
B B B  B B B  B B B  B B B  <xsl:for-each-group
select="location[xs:integer(class) gt 6]"
group-by="city">
B B B  B B B  B B B  B B B  B B B  <tr>
B B B  B B B  B B B  B B B  B B B  B B B  <td>7-10</td>
B B B  B B B  B B B  B B B  B B B  B B B  <td><xsl:value-of
select="format-number(sum(current-group()/value),'$###,###')"/></td>
B B B  B B B  B B B  B B B  B B B  </tr>
B B B  B B B  B B B  B B B  </xsl:for-each-group>
B  B  B  B  B  B  B  </xsl:variable>
B  B  B  B  B  B  B  <xsl:perform-sort select="$rows">
B  B  B  B  B  B  B  B  B  <xsl:sort select="xs:decimal(replace(td[2], '[,$]',
''))" order="descending"/>
B  B  B  B  B  B  B  </xsl:perform-sort>

Having to do the replace after the formatting is probably not the right
approach but you could in the first step only store the number values
and in the second step sort and format if wanted.

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.