Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - xsl grouping and suming by date ranges [Thread Next] Re: xsl grouping and suming by date rangesTo: 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 < $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 < $max-year">
<th>
<xsl:value-of select="sum(key('tradeIdKey',
$id)[substring(@mfd, 7, 4) >= $year and substring(@mfd, 7, 4) <
($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
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
