[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Maximum number of cells
Subject: RE: [xsl] Maximum number of cells From: "Dudley, Mark" <Mark.Dudley@xxxxxxxxxxxxx> Date: Thu, 21 Dec 2000 08:30:39 -0500 |
Hello, For everyone's information, here is the XSLT I ended up using to solve the problem: <xsl:template match="table"> <xsl:variable name="xxx"> <xsl:apply-templates select="row"> <xsl:sort data-type="number" order="descending" select="count(cell)" /> </xsl:apply-templates> </xsl:variable> <xsl:value-of select="substring($xxx,1,1)"/> </xsl:template> <xsl:template match="row"> <xsl:value-of select="count(cell)"/> </xsl:template> Thanks again. Mark Dudley -----Original Message----- From: Dudley, Mark [mailto:Mark.Dudley@xxxxxxxxxxxxx] Sent: Thursday, December 21, 2000 8:08 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: RE: [xsl] Maximum number of cells Thank you all for your help. This list is an excelleent resource for developers and its because of people like you! Mark -----Original Message----- From: Steve Muench [mailto:Steve.Muench@xxxxxxxxxx] Sent: Wednesday, December 20, 2000 6:03 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Maximum number of cells Here's a solution that does what I think you're trying to achieve (generate an appropriate colspan="xxx" for rows that have fewer than the max(cells) number of cells) Given your input: <table> <row> <cell>...</cell> </row> <row> <cell>...</cell> <cell>...</cell> <cell>...</cell> </row> <row> <cell>...</cell> <cell>...</cell> </row> </table> the stylesheet below produces the output: <html> <body> <table> <tr> <td colspan="3">...</td> </tr> <tr> <td>...</td> <td>...</td> <td>...</td> </tr> <tr> <td>...</td> <td colspan="2">...</td> </tr> </table> </body> </html> Here's the stylesheet: <x:stylesheet xmlns:x="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- Compute the max(count(cell)) for all <row> elements --> <x:variable name="maxcells"> <x:for-each select="/table/row"> <x:sort data-type="number" order="descending" select="count(cell)"/> <x:if test="position()=1"><x:value-of select="count(cell)"/></x:if> </x:for-each> </x:variable> <x:template match="cell"> <td> <!-- If we're processing the last cell and $maxcells is greater --> <x:if test="position()=last() and $maxcells > position()"> <x:attribute name="colspan"> <x:value-of select="$maxcells - position() + 1"/> </x:attribute> </x:if> <x:apply-templates/> </td> </x:template> <x:template match="/"> <html><body> <x:apply-templates/> </body></html> </x:template> <x:template match="table"> <table> <x:apply-templates select="row"/> </table> </x:template> <x:template match="row"> <tr> <x:apply-templates select="cell"/> </tr> </x:template> </x:stylesheet> ______________________________________________________________ Steve Muench, Lead XML Evangelist & Consulting Product Manager BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG Author "Building Oracle XML Applications", O'Reilly http://www.oreilly.com/catalog/orxmlapp/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Maximum number of cells, Dudley, Mark | Thread | [xsl] NEWBIE: Instant Saxon and Uni, Graham Diehl |
[xsl] Which XSL DTD to use and how , Uri Goldstein | Date | [xsl] Saxon 6.0.2 : How does it han, Ted Rice |
Month |