RE: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14)
2005-05-05 02:47:36
Here my quick attempt at this one...
(I've been off-list for a while and deleted most of the early posts of
this long-thread, so apologies in advance if I've missed anything)
It uses a nested for-each to find the groups, rather than recursion.
It's not as elegant as David's, or as performant, but possibly easier to
understand :)
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="A">
<result>
<!-- Get the end of each group -->
<xsl:for-each select="B[(_at_)period_end <
following-sibling::B[1]/@period_begin or not(following-sibling::B)]">
<xsl:variable name="end" select="@period_end"/>
<xsl:variable name="endOfGroup" select="generate-id()"/>
<!-- Get the start for this end -->
<xsl:for-each select="(preceding-sibling::B[(_at_)period_begin >
preceding-sibling::B[1]/@period_end or
not(preceding-sibling::B)])[last()]">
<period begins="{(_at_)period_begin}" end="{$end}">
<!-- Copy all elements between start and end -->
<xsl:copy-of select=".|following-sibling::B[generate-id() =
$endOfGroup or following-sibling::B[generate-id() = $endOfGroup]]"/>
</period>
</xsl:for-each>
</xsl:for-each>
</result>
</xsl:template>
</xsl:stylesheet>
Cheers
andrew
--~------------------------------------------------------------------
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>
--~--
<Prev in Thread] |
Current Thread |
[Next in Thread>
|
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), (continued)
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), David Carlisle
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), Karl Stubsjoen
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14, Aron Bock
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14, Aron Bock
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), David Carlisle
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14, Aron Bock
- Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), Wendell Piez
Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), Dimitre Novatchev
RE: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14),
Andrew Welch <=
Re: A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14), Mukul Gandhi
|
|
|