[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:07:56 -0500 |
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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Maximum number of cells, Miloslav Nic | Thread | RE: [xsl] Maximum number of cells, Dudley, Mark |
Re: [xsl] Dynamic sort order.., Michael Hoffmann | Date | [xsl] Which XSL DTD to use and how , Uri Goldstein |
Month |