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

Re: XHTML to CALS table

Subject: Re: XHTML to CALS table
From: uche.ogbuji@xxxxxxxxxxxxxxx
Date: Tue, 21 Nov 2000 23:10:12 -0700
docbook colspan
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'>
    <TABLE>
      <xsl:if test="@frame='none'">
        <xsl:attribute name='border'>0</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
    </TABLE>
  </xsl:template>
  
  <xsl:template match='doc:row'>
    <TR>
      <xsl:apply-templates/>
    </TR>
  </xsl:template>
  
  <xsl:template match='doc:entry'>
    <xsl:choose>
      <xsl:when test='@spanname'>
        <xsl:variable name="spanspec" select="ancestor::doc:table[1]/doc:spansp
ec[@spanname=current()/@spanname]"/>
        <!-- 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
c"/>
        <xsl:variable name="start" select="count($colspecs[@colname=$spanspec/@
namest]/preceding-sibling::doc:colspec)+1"/>
        <xsl:variable name="end" select="count($colspecs[@colname=$spanspec/@na
meend]/preceding-sibling::doc:colspec)+1"/>
        <xsl:variable name="colspan" select="$end - $start"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="colspan"/>
      </xsl:otherwise>
    </xsl:choose>
    <TD>
      <xsl:if test="$colspan">
        <xsl:attribute name='COLSPAN'><xsl:value-of select="$colspan"/>
</xsl:attribute>
      </xsl:if>
      <xsl:apply-templates/>
    </TD>
  </xsl:template>
  
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 http://docbook.org)

Good luck.


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



 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.