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

Re: Maximum number of cells

Subject: Re: Maximum number of cells
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Wed, 20 Dec 2000 15:02:40 -0800
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


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.