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) < $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)
> $one-year-cut-off">
<xsl:for-each-group select="current-group()"
group-by="xs:date(cmn:Metadata/dcterms:created) < $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) > $six-months-cut-off">
<xsl:for-each-group
select="current-group()"
group-by="xs:date(cmn:Metadata/dcterms:created) <
$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) > $three-months-cut-off">
<xsl:for-each-group
select="current-group()"
group-by="xs:date(cmn:Metadata/dcterms:created) <
$one-month-cut-off"> <xsl:sort
select="cmn:Metadata/dcterms:created" order="descending" />
<xsl:choose>
<xsl:when
test="xs:date(cmn:Metadata/dcterms:created) > $one-month-cut-off">
<xsl:for-each-group select="current-group()"
group-by="xs:date(cmn:Metadata/dcterms:created) <
$one-week-cut-off">
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) >
$one-week-cut-off">
<xsl:for-each-group select="current-group()"
group-by="xs:date(cmn:Metadata/dcterms:created) <= $today">
<xsl:choose>
<xsl:when test="xs:date(cmn:Metadata/dcterms:created) >=
$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
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--