This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XHTML to CALS table
- To: xsl-list at mulberrytech dot com
- Subject: Re: XHTML to CALS table
- From: uche dot ogbuji at fourthought dot com
- Date: Tue, 21 Nov 2000 23:10:12 -0700
- Reply-To: xsl-list at mulberrytech dot com
Ben Skelton <Ben_Skelton@habaneros.com>:
> >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@fourthought.com +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