我想通过TBODY创建分开由THEAD和数据行标题行的表结构:XSLT +创建表结构
输入XML:
<Rowsets>
<Rowset>
<Columns>
<Column Description="Date"/>
<Column Description="Time"/>
</Columns>
<Row>
<Date>DATA1</Date>
<Time>DATA2</Time>
</Row>
<Row>
<Date>DATA1</Date>
<Time>DATA2</Time>
</Rowset>
</Rowsets>
以下XSLT确实会分隔标题和正文,但我无法弄清楚如何在数据行之间打包标记:
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<HTML>
<BODY>
<TABLE>
<XSL:apply-templates/>
</TABLE>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="Columns|Row">
<tr><xsl:apply-templates/></tr>
</xsl:template>
<xsl:template match="Columns">
<thead><xsl:apply-templates/></thead>
</xsl:template>
<xsl:template match="Columns/*">
<th><xsl:apply-templates select="@Description"/></th>
</xsl:template>
<xsl:template match="Row/*">
<td><xsl:apply-templates/></td>
</xsl:template>
当前HTML输出:
<THEAD>
<TR>
<TH>Date</TH><TH>Time</TH>
</TR>
</THEAD>
<TR>
<TD>DATA1</TD><TD>DATA2</TD>
</TR>
<TR>
<TD>DATA1</TD><TD>DATA2</TD>
</TR>
如何我TBODY包装数据行?谢谢!
因为只匹配“Columns”的模板具有更高的默认优先级(正在存在),所以匹配'“Columns | Row”'的模板将永远不会应用到'“Columns”更具体)。所以你不妨将'match ='Columns | Row''更改为'match =“Row”',以减少阅读时的混淆。 – LarsH 2012-01-12 18:10:26