Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: xsl grouping and suming by date ranges

From: "Oleg Tkachenko [MVP]" <oleg@--!----!---------------.--->
To: NULL
Date: 12/1/2004 11:51:00 AM
dk wrote:

> is it possible to take the xml code below and create a grid with xsl

Sure :)

> where i can group the mfd ranges (say all dates within now+3 years, then
> the 
> next 3 years, and then next 3 years)
> and then sum the ttblack field for those ranges so that
> a grid would be created with  rows as follows:
> 
> 
>                            now -2007        2008-2011  2012-2015             
>    
> TEST                        300                   200           100
> TEST1                         30                   10               5
> Total                          330                   210           105
> 
> 
> the numbers are not correct, but is the idea clear?
> 
> any ideas?
> 	<Step mfd="11/18/2005" TTBlack="2,035"/>

Can you make it 2.035 ?
Here is some unoptimized and untested sketch:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:key name="tradeIdKey" match="Step" 
use="preceding-sibling::TradeId[1]"/>
   <xsl:param name="now" select="2004"/>
   <xsl:param name="step" select="3"/>
   <xsl:variable name="max-year">
     <xsl:for-each select="/Portfilio/Trade/Step/@mfd">
       <xsl:sort select="substring(., 7, 4)" data-type="number" 
order="descending"/>
       <xsl:if test="position()=1">
         <xsl:value-of select="substring(., 7, 4)"/>
       </xsl:if>
     </xsl:for-each>
   </xsl:variable>
   <xsl:variable name="number-of-columns" select="($max-year - $now) div 
$step"/>
   <xsl:template match="/">
     <table>
       <tr>
         <th>TradeId</th>
         <xsl:call-template name="header">
           <xsl:with-param name="year" select="$now"/>
         </xsl:call-template>
       </tr>
       <xsl:apply-templates select="/Portfilio/Trade/TradeId"/>
     </table>
   </xsl:template>
   <xsl:template name="header">
     <xsl:param name="year"/>
     <xsl:if test="$year &lt; $max-year">
       <th>
         <xsl:value-of select="$year"/> - <xsl:value-of select="$year + 
$step"/>
       </th>
       <xsl:call-template name="header">
         <xsl:with-param name="year" select="$year + $step"/>
       </xsl:call-template>
     </xsl:if>
   </xsl:template>
   <xsl:template match="TradeId">
     <tr>
       <td><xsl:value-of select="."/></td>
       <xsl:call-template name="content">
         <xsl:with-param name="year" select="$now"/>
         <xsl:with-param name="id" select="."/>
       </xsl:call-template>
     </tr>
   </xsl:template>
   <xsl:template name="content">
     <xsl:param name="year"/>
     <xsl:param name="id"/>
     <xsl:if test="$year &lt; $max-year">
       <th>
         <xsl:value-of select="sum(key('tradeIdKey', 
$id)[substring(@mfd, 7, 4) >= $year and substring(@mfd, 7, 4) &lt; 
($year + $step)]/@TTBlack)"/>
       </th>
       <xsl:call-template name="content">
         <xsl:with-param name="year" select="$year + $step"/>
         <xsl:with-param name="id" select="$id"/>
       </xsl:call-template>
     </xsl:if>
   </xsl:template>
</xsl:stylesheet>


-- 
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent