xsl-list
[Top] [All Lists]

Re: [xsl] Need help sorting groups

2017-01-09 08:36:51
On 09.01.2017 15:25, Steve Wisniewski stevewiz76(_at_)yahoo(_dot_)com 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

              <xsl:variable name="rows" as="element(tr)*">
<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>
              </xsl:variable>
              <xsl:perform-sort select="$rows">
<xsl:sort select="xs:decimal(replace(td[2], '[,$]', ''))" order="descending"/>
              </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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>
  • Re: [xsl] Need help sorting groups, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de <=