HTML for CALS tables?

I am checking to see if anyone has an XSLT that turns HTML tables into CALS. I found a lot of material in a different way (CALS to HTML), but not from HTML. I thought someone might have done this before, so I don't need to reinvent the wheel. I am not looking for a complete solution. Just a starting point.

If I get enough, I will send it for future reference.

+5
source share
3 answers

I came up with a much simpler solution than the one related to @Flack:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="tbody">
    <xsl:variable name="maxColumns">
        <xsl:for-each select="tr">
            <xsl:sort select="sum(td/@colspan) + count(td[not(@colspan)])" data-type="number"/>
            <xsl:if test="position() = last()">
                <xsl:value-of select="sum(td/@colspan) + count(td[not(@colspan)])"/>
            </xsl:if>
        </xsl:for-each>
    </xsl:variable>
    <tgroup>
        <xsl:attribute name="cols">
            <xsl:value-of select="$maxColumns"/>
        </xsl:attribute>
        <xsl:apply-templates select="@*|node()"/>
    </tgroup>
</xsl:template>

<xsl:template match="td[@colspan > 1]">
    <entry>
        <xsl:attribute name="namest">
            <xsl:value-of select="sum(preceding-sibling::td/@colspan) + count(preceding-sibling::td[not(@colspan)]) + 1"/>
        </xsl:attribute>
        <xsl:attribute name="nameend">
            <xsl:value-of select="sum(preceding-sibling::td/@colspan) + count(preceding-sibling::td[not(@colspan)]) + @colspan"/>
        </xsl:attribute>
        <xsl:apply-templates select="@*[name() != 'colspan']|node()"/>
    </entry>
</xsl:template>

<xsl:template match="tr">
    <row>
        <xsl:apply-templates select="@*|node()"/>
    </row>
</xsl:template>

<xsl:template match="td">
    <entry>
        <xsl:apply-templates select="@*|node()"/>
    </entry>
</xsl:template>

<xsl:template match="td/@rowspan">
    <xsl:attribute name="morerows">
        <xsl:value-of select=". - 1"/>
    </xsl:attribute>
</xsl:template>

<!-- fallback rule -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>
</xsl:stylesheet>

. -, CALS tgroup/@cols, . XHTML, colspan, colspan > 1 ! @Tim C max .

, XHTML , " 3 " (colspan = "3" ), CALS , " 2 4" (namest = "2" nameend = "4" ). .

. , = ": 50%" = "50%" .., , .

+4
+1

Although I do not understand the particular difficulty, I looked for some of them:

0
source

All Articles