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

Re:Re:An XSLT equivalent of SQL SUM and GROUP BY opera

Subject: Re:Re:An XSLT equivalent of SQL SUM and GROUP BY operations?
From: "Yang" <sfyang@xxxxxxxxxxxxx>
Date: Wed, 23 May 2001 09:37:32 +0800
sql sum variable
Hi, all,

Jeni have given  basic elements for this data base problem.
Now on the top of her suggestions,  I add **SORT BY SUM** request to
the SQL  equivalent problem.  Hope Jeni can provide more input to my
addition.

To gain efficiency by saving computed effort with sum() function, I am using
two step approach.  The first step is to get data ready from using
apply-templates element

and then wrap the data with variable **tempResult**.

<xsl:variable name="tempResult">
  <xsl:apply-templates
     select="//line[count(.|key('lines', concat(Account, ':', Date))[1])
                  = 1]" mode="unique"/>
</xsl:variable>

In the second step, it is to sort and display the solution using parser
related extension node-set function,  such as:

<xsl:apply-templates select="msxsl:node-set($tempResult)/line" mode="table">
        <xsl:sort select="Amount" order="descending" data-type="number"/>
</xsl:apply-templates>

Hope it will be helpful.

Sun-fu Yang

sfyang@xxxxxxxxxxxxx
<?xml version="1.0"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:msxsl="urn:schemas-microsoft-com:xslt" >
<xsl:output method="html" indent="yes"/>


<xsl:key name="lines"
         match="line"
         use="concat(Account, ':', Date)" />

<xsl:template match="/">
   <html>
      <head>
      </head>
  <xsl:variable name="tempResult">
  <xsl:apply-templates
     select="//line[count(.|key('lines', concat(Account, ':', Date))[1])
                  = 1]" mode="unique"/>

  <!--xsl:apply-templates
     select="//line[generate-id(.) =
  generate-id(key('lines', concat($line/Account, ':' $line/Date))[1])
                  = 1]" /-->
 </xsl:variable>
  <table>
  <tr><th>account</th><th>date</th><th>amount</th></tr>
  <xsl:apply-templates select="msxsl:node-set($tempResult)/line"
mode="table">
 <xsl:sort select="Amount" order="descending" data-type="number"/>
  </xsl:apply-templates>
  </table>

</html>
</xsl:template>

<xsl:template match="line" mode="unique">
   <line>
      <xsl:copy-of select="Account | Date" />
      <Amount>
         <xsl:value-of
            select="sum(key('lines',
                            concat(Account, ':', Date))/Amount)" />
      </Amount>
   </line>
</xsl:template>

<xsl:template match="line" mode="table">

<tr>
<td><xsl:value-of select="Account"/></td>
<td><xsl:value-of select="Date"/></td>
<td><xsl:value-of select="Amount"/></td>
</tr>
</xsl:template>

</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.