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>
<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%" .., , .