我需要显示两个表:
| 参数1 | 参数2 | --------+------+---------- | p1.1 | p1.2 | p2 | --------+------+---------- | a11 | a21 | b01 | | a12 | a22 | b02 | | Col1 | Col2 | --------+------+---------- | c1.1 | c1.2 | c2 | --------+------+---------- | x11 | x21 | y01 | | x12 | x22 | y02 |
XML:
<?xml version="1.0" encoding="UTF-8"?>
<tb>
<col title="Param1">
<row name="1">
<stats name="p1.1" >a11</stats>
<stats name="p1.2" >a21</stats>
</row>
<row name="2">
<stats name="p1.1" >a12</stats>
<stats name="p1.2" >a22</stats>
</row>
</col>
<col title="Param2">
<row name="1">
<stats name="p2" >b01</stats>
</row>
<row name="2">
<stats name="p2" >b02</stats>
</row>
</col>
</tb>
<tb>
<col title="Col1">
<row name="1">
<stats name="c1.1" >x11</stats>
<stats name="c1.2" >x21</stats>
</row>
<row name="2">
<stats name="c1.1" >x12</stats>
<stats name="c1.2" >x22</stats>
</row>
</col>
<col title="Col2">
<row name="1">
<stats name="c2" >y01</stats>
</row>
<row name="2">
<stats name="c2" >y02</stats>
</row>
</col>
</tb>
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/tb">
<table class="data_table" style="width: 100%; background:gray">
<thead>
<tr>
<xsl:apply-templates select="col" mode="titles" />
</tr>
<tr>
<xsl:apply-templates select="col/row[1]/stats" mode="titles" />
</tr>
</thead>
<tbody>
<xsl:apply-templates select="col[1]/row" />
</tbody>
</table>
</xsl:template>
<xsl:template match="col" mode="titles">
<th>
<xsl:apply-templates select="(.)[row[1]/stats[2]]" mode="colSpan" />
<xsl:value-of select="@title"/>
</th>
</xsl:template>
<xsl:template match="col" mode="colSpan">
<xsl:attribute name="colspan">
<xsl:value-of select="count(row[1]/stats)"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="stats" mode="titles">
<th>
<xsl:value-of select="@name" />
</th>
</xsl:template>
<xsl:template match="row">
<tr>
<xsl:apply-templates select="../../col/row[@name = current()/@name]/stats" />
</tr>
</xsl:template>
<xsl:template match="stats">
<td>
<xsl:value-of select="." />
</td>
</xsl:template>
</xsl:stylesheet>
但是我在两个表之间进行了合并,如下所示:
| 参数1 | 参数2 | Col1 | Col2 | --------+------+--------+------+------+-------- | p1.1 | p1.2 | p2 | c1.1 | c1.2 | c2 | --------+------+--------+------+------+-------- | a11 | a21 | b01 | x11 | x21 | y01 | | a12 | a22 | b02 | x12 | x22 | y02 |
如何避免表之间的合并?