我想让我的头绕过XSL递归。我需要使用带有单元标签的XSLT构建基于XML的HTML表格,其中位置映射到名为格式为“row.column”的名称的字符串属性。基于变量的XSL递归遍历
我想递归地从最后一个单元格开始计数回到第一个单元格(0.0)并开始构建表格。原因是有些单元可能跨越几个单元位置。因此,为了在HTML中使用,我不能只在for-each循环中处理单元格。最后一个单元格由表格属性标识; BodyRowCount和ColumnCount。
的XML看起来像这样
<Table HeaderRowCount="0" FooterRowCount="0" BodyRowCount="4" ColumnCount="2" >
\t <Cell Self="ucd8iceei0" Name="0:0" RowSpan="1" ColumnSpan="1">
\t \t <Content>1</Content>
\t </Cell>
\t <Cell Self="ucd8iceei1" Name="1:0" RowSpan="1" ColumnSpan="1">
\t \t <Content>2</Content>
\t </Cell>
\t <Cell Self="ucd8iceei2" Name="2:0" RowSpan="1" ColumnSpan="2>
\t \t <Content>3</Content>
\t </Cell>
\t <Cell Self="ucd8iceei3" Name="3:0" RowSpan="1" ColumnSpan="1">
\t \t <Content>4</Content>
\t </Cell>
\t <Cell Self="ucd8iceei4" Name="0:1" RowSpan="1" ColumnSpan="1">
\t \t <Content>5</Content>
\t </Cell>
\t <Cell Self="ucd8iceei6" Name="2:1" RowSpan="1" ColumnSpan="1">
\t \t <Content>7</Content>
\t </Cell>
\t <Cell Self="ucd8iceei7" Name="3:1" RowSpan="1" ColumnSpan="1">
\t \t <Content>8</Content>
\t </Cell>
</Table>
结果应该是这样的
<Table>
\t <tr>
\t \t <td>1</td> \t <td>5</td>
\t </tr>
\t <tr>
\t \t <td> colspan="2">2</td>
\t </tr>
\t <tr>
\t \t <td>3</td> <td>7</td>
\t </tr>
\t <tr>
\t \t <td>4</td> \t <td>8</td>
\t </tr>
</Table>
伪形式的XLS在下面。我尝试在名为4.2的Cell中传递参数以开始这种情况,但似乎是不合法的,不能通过基于属性的参数,但是这肯定是可能的?
<xsl:template match="Table"> \t
\t <table>
\t \t <xsl:apply-templates select="Cell[@Name = concat(@BodyRowCount,':',ColumnCount)']"/>
\t </table>
</xsl:template>
<xsl:template name="Cell[@name='0.0">
Found first cell, start first row in table
<tr><td colspan=<xsl:value-of select=(concat(3",@ColumnSpan,3")) rowspan=<xsl:value-of select=(concat(3",@rowSpan,3"))> Row content here </td></tr>
</xsl:template>
<xsl:template name="Cell[@name='0.*">
\t Call template with 'ROW-1, COLUMN back to max
\t <xsl:apply-templates select="Cell[@Name = 'ROW-1:MAXCOLUMN']">
\t new row goes here
\t <tr><td colspan=<xsl:value-of select=(concat(3",@ColumnSpan,3")) rowspan=<xsl:value-of select=(concat(3",@rowSpan,3"))> Row content here </td></tr>
</xsl:template>
<xsl:template name="Cell[@name='*.*">
\t Call template with one column before
\t <xsl:apply-templates select="Cell[@Name = SAME ROW:COLUMN-1']">
\t <td colspan=<xsl:value-of select=(concat(3",@ColumnSpan,3")) rowspan=<xsl:value-of select=(concat(3",@rowSpan,3"))> Row content here </td>
</xsl:template>
我寻找关于如何启动的递归循环中4.2回到0.0,通过遍历所有的位置,如果一个存在插入单元格的值建表一些帮助?
您在使用XSLT 1.0和XSLT 2.0? –
嗨我使用V2,但如果我更改为V1,那么Andreas提供的示例没有错误地工作。所以看起来版本的行为有所不同。 – Christian
如果您使用XSLT 2.0,那么您可以使用内置的分组功能。 - 你能解释一下什么决定了这个colspan?在你的例子中,每个单元格都有RowSpan和ColumnSpan属性 - 但是你的输出具有不同的值。这是为什么? –