所以我有一个描述这样的表的 XML 文档
<Section Columns="1" Id="2" Name="DataTable">
<DataTable Name="TestDataTable">
<DisplayOptions Column="1" />
<TableOptions Appendable="true" />
<Header Name="tableHeader">
<Label isCurrency="false">Unit</Label>
<Label isCurrency="false">type</Label>
<Label isCurrency="false">Min</Label>
<Label isCurrency="false">Max</Label>
.... more label for the header
</Header>
<Row>
<Label>A unit</Label>
<DataField Id="312" Name="unit1" ControlType="Text">
<FieldOptions Visibility="true" isCurrency="false"/>
</DataField>
.... more datafield
</Row>
... more rows
<footer name="tableFooter">
<Label>Total # of Units:</Label>
<Label>0</Label>
... more label
</footer>
和一个 XSLT 样式表,它使用该 XML 来创建一个使用 HTML 的表,如下所示:
<xsl:template match="Header">
<thead>
<xsl:for-each select="Label">
<th class="dataTableHeader">
<xsl:variable name="currentPosition" select="position() - 1"/>
<label>
<xsl:value-of select="self::node()"/>
</label>
</th>
</xsl:for-each>
</thead>
</xsl:template>
<xsl:template match="footer">
<tfoot>
<tr>
<xsl:for-each select="Label">
<th class="dataTableFooter">
<xsl:variable name="currentPosition" select="position() - 1"/>
<label name="Silly">
<xsl:value-of select="self::node()"/>
</label>
</th>
</xsl:for-each>
</tr>
</tfoot>
</xsl:template>
<xsl:template match="Row">
<tr class="tableRow">
<!-- apply the template flag if it is there -->
<xsl:if test="@Template = 'true'">
<xsl:attribute name="data-is-template" />
</xsl:if>
<!-- there should only be one label in each row -->
<xsl:if test="Label">
<td class="dataTableRowTitle">
<label for="{DataField[1]/@Id}">
<xsl:value-of select="Label"/>
</label>
</td>
</xsl:if>
<!-- apply the datafield templates in table mode -->
<xsl:apply-templates select="DataField" mode="tableInput" />
</tr>
</xsl:template>
<xsl:template match="Label">
<xsl:value-of select="self::text()"/>
</xsl:template>
问题是 XSLT 将 tfooter 呈现为 tbody 的一行,而不是将其分开。我检查了 html 并且 tfooter 是 tbody 的子项。这只发生在 Firefox 中;它在所有其他主要浏览器中都很好用。
<td colspan="2">
<table class="dataTable">
<thead>...</thead>
<tbody>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tfoot>...</tfoot>
</tbody>
</table>
</td>
当我检查其他浏览器时,我发现 tfooter 是 tbody 和 theader 的兄弟。
<td colspan="2">
<table class="dataTable">
<thead>...</thead>
<tbody>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
</tbody>
<tfoot>...</tfoot>
</table>
</td>
所以我将 XML 中的页脚部分移到了 Header 和 Row 之间,现在它可以工作了。tfooter 现在是 tbody 和 theader 的兄弟,并且在 tbody 之前。
<td colspan="2">
<table class="dataTable">
<thead>...</thead>
<tfoot>...</tfoot>
<tbody>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
<tr class="tableRow"></tr>
</tbody>
</table>
</td>
所以问题是 Firefox 为什么要这么做?这是一个错误还是Firefox在创建表格时首先在行之前呈现页眉和页脚,所以我们必须在XSLT中首先处理页眉和页脚?