Chris G
Chris G

Reputation: 21

XSLT tables out of order in output

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.

Upvotes: 0

Views: 100

Answers (1)

Alohci
Alohci

Reputation: 82986

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.

Upvotes: 0

Related Questions