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

A more elegant solution to unpredictable ranges?

Subject: A more elegant solution to unpredictable ranges?
From: Fraser Crichton <fc@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 19 Jun 2007 10:25:29 +0100
 A more elegant solution to unpredictable ranges?
Hi,

I'm looking for some advice on refactoring the following ugliness, I think my problem is that I have an unpredictable range of dates to loop over -

<xsl:variable name="today" select="xs:date('2008-02-01')"/>
<xsl:variable name="one-year-cut-off" select="research:cutOffDate('P365D')"/>
<xsl:variable name="six-months-cut-off" select="research:cutOffDate('P182D')"/>
<xsl:variable name="three-months-cut-off" select="research:cutOffDate('P90D')"/>
<xsl:variable name="one-month-cut-off" select="research:cutOffDate('P30D')"/>
<xsl:variable name="one-week-cut-off" select="research:cutOffDate('P7D')"/>


and so it's hard to build up a recursive template. The only thing I can think of is having a kind of pseudo array structure which I submit to the template as a nodeset otherwise I end up with this -

<xsl:template name="group-by-date-created">
<xsl:for-each-group select="funding:Call" group-by="xs:date(cmn:Metadata/dcterms:created) &lt; $one-year-cut-off">
<xsl:sort select="cmn:Metadata/dcterms:created" order="{$sort-order}" />
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt; $one-year-cut-off">
<xsl:for-each-group select="current-group()" group-by="xs:date(cmn:Metadata/dcterms:created) &lt; $six-months-cut-off">
<xsl:sort select="cmn:Metadata/dcterms:created" order="{$sort-order}" />
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt; $six-months-cut-off">
<xsl:for-each-group select="current-group()" group-by="xs:date(cmn:Metadata/dcterms:created) &lt; $three-months-cut-off"> <xsl:sort select="cmn:Metadata/dcterms:created" order="{$sort-order}" />
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt; $three-months-cut-off">
<xsl:for-each-group select="current-group()" group-by="xs:date(cmn:Metadata/dcterms:created) &lt; $one-month-cut-off"> <xsl:sort select="cmn:Metadata/dcterms:created" order="descending" />
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt; $one-month-cut-off">
<xsl:for-each-group select="current-group()" group-by="xs:date(cmn:Metadata/dcterms:created) &lt; $one-week-cut-off"> <xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt; $one-week-cut-off">
<xsl:for-each-group select="current-group()" group-by="xs:date(cmn:Metadata/dcterms:created) &lt;= $today">
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) &gt;= $one-week-cut-off">
<xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'this-week'"/>
</xsl:call-template>


</xsl:when>
<xsl:otherwise>


<xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'one-week-?'"/>
</xsl:call-template>


</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'one-week-plus'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>


</xsl:for-each-group>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'one-month-plus'"/>
</xsl:call-template> </xsl:otherwise>
</xsl:choose>
</xsl:for-each-group> </xsl:when>
<xsl:otherwise> <xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'three-months-plus'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:when>
<xsl:otherwise> <xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'six-months-plus'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group> </xsl:when>
<xsl:otherwise>
<xsl:call-template name="current-group">
<xsl:with-param name="groupName" select="'one-year-plus'"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>


Any advice would be much appreciated,

Cheers,

Fraser

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.