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

RE: Grouping adjacent columns in a table

Subject: RE: Grouping adjacent columns in a table
From: Emmanuel Begue <eb@xxxxxxxxxx>
Date: Fri, 15 Jan 2010 17:48:04 +0100
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

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.