0
votes

I have tables like this:
< table hidden="" class="table">
    < colgroup data-cols="6">
        < col style="width:.75in;text-align:left" data-colname="col1">
        < col style="width:0.8in;text-align:center" data-colname="col2">
        < col style="width:0.76in;" data-colname="col3">
        < col style="width:2.47in;" data-colname="col4">
        < col style="text-align:left" data-colname="col5">
        < col style="width:0.8in;text-align:center" data-colname="col6">
        < thead>
            < tr class="headerRow">
                < th>Text< /th>
                < th>Texttext< /th>
                < th>Text< /th>
                < th>Text< /th>
                < th>Text< /th>
                < th>Text Text< /th>
            < /tr>
        < /thead>
        < tbody>
            < tr>
                < td>< span hidden="" class="num">< /td>
                < td>Text< /td>
                < td>Text< /td>
                < td>Text< /td>
                < td>Text< /td>
            < /tr>
        < /tbody>
    < /colgroup>
< / table>

I have XSLT Template matches like this (deleted attribute matches because they're not needed for this example):

<xsl:template match="colgroup">
    <tgroup>                    
        <xsl:apply-templates select="descendant::col | descendant::thead | descendant::tbody"/>
    </tgroup>
</xsl:template>

<xsl:template match="col">
    <colspec>         
        <xsl:apply-templates/>
    </colspec>
</xsl:template>

<xsl:template match="thead">
    <thead>                       
        <xsl:apply-templates />
    </thead>
</xsl:template>

<xsl:template match="tbody">
    <tbody>                      
        <xsl:apply-templates/>
    </tbody>
</xsl:template>

The result I am getting is:
< table hidden="" class="table">
    < tgroup data-cols="6">
        < colspec style="width:.75in;text-align:left" data-colname="col1">
        < colspec style="width:0.8in;text-align:center" data-colname="col2">
        < colspec style="width:0.76in;" data-colname="col3">
        < colspec style="width:2.47in;" data-colname="col4">
        < colspec style="text-align:left" data-colname="col5">
        < colspec style="width:0.8in;text-align:center" data-colname="col6">
      < /tgroup>
      < thead>
            < row class="headerRow">
                < entry>Text< /entry>
                < entry>Texttext< /entry>
                < entry>Text< /entry>
                < entry>Text< /entry>
                < entry>Text< /entry>
                < entry>Text Text< /entry>
            < /row>
        < /thead>
        < tbody>
            < row>
                < entry>< span hidden="" class="num">< /entry>
                < entry>Text< /entry>
                < entry>Text< /entry>
                < entry>Text< /entry>
                < entry>Text< /entry>
            < /row>
        < /tbody>
< / table>

The THEAD and TBODY should be inside the colgroup at the same level as the COL elements, but I can't seem to get it to cooperate.

1
In addition to Alochi's answer, it looks like none of your templates are getting matched anyway, If the "colgroup" one is matched, the output should contain a "tgroup" element, which is not the case if your output is accurate. Does your actual html input contain a namespace declaration of the form xmlns="http://www.w3.org/1999/xhtml"?Tim C
How are you doing the transformation and how are you viewing the output? If you are sending the output to an HTML engine of any kind, then it will try to reorganize the table to make it HTML-valid.Michael Kay

1 Answers

0
votes

You're producing HTML output. In HTML, colgroups only contain col elements, not thead or tbody elements. Your outputter is fixing your HTML for you.

If you don't want that to happen, don't ask your outputter to generate HTML.