Re: XHTML to CALS table

Subject: Re: XHTML to CALS table
From: uche.ogbuji@xxxxxxxxxxxxxxx
Date: Tue, 21 Nov 2000 23:10:12 -0700
Ben Skelton <Ben_Skelton@xxxxxxxxxxxxx>:

> >I was wondering if anyone has a stylesheet or has had any experience converting
> >HTML (or XHTML) tables to CALS tables using XSLT. The biggest problems I see in
> >doing this is that colspan and rowspans are treated differently. Any help would
> >be much appreciated!

I almost hesitate to post this, because it might just be useless to you, but I 
see you haven't had much response so maybe anything is better than nothing.

Docbook basically uses the CALS model, and so you might be able to extrapolate 
from my docbook -> HTML transform which only handles the rowspec/colspec to 
colspan portion.  I think that one of these days I'll finish it off, but first 
of all I'll want to clean up the code.  Anyway, here is the relevant snippet:

  <xsl:template match='doc:table'>
      <xsl:if test="@frame='none'">
        <xsl:attribute name='border'>0</xsl:attribute>
  <xsl:template match='doc:row'>
  <xsl:template match='doc:entry'>
      <xsl:when test='@spanname'>
        <xsl:variable name="spanspec" select="ancestor::doc:table[1]/doc:spansp
        <!-- FIXME: This logic will break if a colspec has a colnum attr out 
of sequence -->
        <xsl:variable name="colspecs" select="ancestor::doc:table[1]/doc:colspe
        <xsl:variable name="start" select="count($colspecs[@colname=$spanspec/@
        <xsl:variable name="end" select="count($colspecs[@colname=$spanspec/@na
        <xsl:variable name="colspan" select="$end - $start"/>
        <xsl:variable name="colspan"/>
      <xsl:if test="$colspan">
        <xsl:attribute name='COLSPAN'><xsl:value-of select="$colspan"/>
I've done no work to optimize this whatsoever.  If you do come up with 
something useful, I'd love to see it.

Meanwhile, it's possible that you'll find a better answer in Norm Walsh's far 
more comprehensive docbook -> html stylesheet (see

Good luck.

Uche Ogbuji                               Principal Consultant
uche.ogbuji@xxxxxxxxxxxxxxx               +1 303 583 9900 x 101
Fourthought, Inc.                
4735 East Walnut St, Ste. C, Boulder, CO 80301-2537, USA
Software-engineering, knowledge-management, XML, CORBA, Linux, Python

 XSL-List info and archive:

Current Thread