Subject: RE: [xsl] A challenge.. Group Periods of Data (1..5, 2..8, 4..9) (10..12; 10..14) From: "Andrew Welch" <ajwelch@xxxxxxxxxxxxxxx> Date: Thu, 5 May 2005 10:47:36 +0100 |
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[@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[@period_begin > preceding-sibling::B[1]/@period_end or not(preceding-sibling::B)])[last()]"> <period begins="{@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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] HELP, Validate generated , Wendell Piez | Thread | Re: [xsl] A challenge.. Group Perio, Mukul Gandhi |
Re: [xsl] HELP, Validate generated , Mukul Gandhi | Date | RE: [xsl] Do Templates Conflict?, Andrew Welch |
Month |