0

所以我有一个描述这样的表的 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中首先处理页眉和页脚?

4

1 回答 1

0

您可能看到的是基于由 XSLT 生成的 XML 生成的 DOM 的 HTML。重要的是要认识到在查看 DOM 时可能会更改文档的来源,这通常是您在 Firefox 的 Firebug 或 IE 的 F12 等开发人员工具中看到的。

例如,您正在查看的内容可能是此步骤的最后一步:

Input XML --[ XSLT ]--> Output HTML --[ Browser API ]--> Resultant DOM

如果您查看HTML4 规范,该<tfoot>元素必须在之前<tbody>而不是之后。HTML5 中的限制已更改,页脚可以位于正文之前或之后,但在从 HTML 文档创建 DOM 时,Mozilla 可能遵循旧规则作为其有效规则。Mozilla Developers Network 页面上<tfoot>有更多关于此的信息,这是我获得一些链接的地方。

于 2013-09-03T23:55:37.793 回答