[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: 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
|
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
|