[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Grouping adjacent columns in a table
> -----Original Message----- > From: Michael Kay [mailto:mike@xxxxxxxxxxxx] > Sent: Friday, January 15, 2010 4:33 PM > Subject: RE: Grouping adjacent columns in a table > > Rather than using for-each-group, I would use recursion: tail > recursion over the sequence of columns, testing each one to see > if it has the same content as the next column. You can do this > test using deep-equals(): given $i as the column number > > deep-equal(tbody/tr/td[$i], tbody/tr/td[$i+1) > > The output of this recursion can be a list of the columns to be > included in the result (in your example (1,2,3,5)) and then you > can use this list to drive the process that builds the output. Using deep-equal (and a key to avoid using //), it's possible to proceed in one pass: <xsl:key name="cols" match="td" use="count(preceding-sibling::*)"/> <xsl:template match="th|td"> <xsl:variable name="pos" select="count(preceding-sibling::*)"/> <xsl:if test="not(deep-equal(key('cols',$pos),key('cols',$pos - 1)))"> <xsl:copy-of select="."/> </xsl:if> </xsl:template> Is it undesirable because it (probably) makes the comparison again for each row (ie, for each column of each row), so if there are many rows it may be slow...? But if there are not many rows, why not? (I feel I'm missing something but I don't know what ;-) (Also, this only works if identical columns are adjacent). Regards, EB
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|