我在看一个类似的问题是什么在这里XSL:将XML为有序多列的HTML表格
Transforming List into a 2-D Table
覆盖但有轻微的皱纹。我的XML没有任何特定的顺序,我想对它进行排序以供显示。例如我的XML是
<items>
<item>A</item>
<item>C</item>
<item>E</item>
<item>B</item>
<item>D</item>
<!-- ... any number of item nodes ... -->
<item>
,我想我的输出是(这里我忽略用于说明目的的非命名节点)
<table>
<tr>
<td>A</td>
<td>C</td>
<td>E</td>
</tr>
<tr>
<td>B</td>
<td>D</td>
<td />
</tr>
</table>
我立足这一关的XSL是从以上的链接(我需要使用XSL 1.0):
<xsl:template match="/*">
<table>
<xsl:call-template name="make-columns">
<xsl:with-param name="nodelist" select="item"/>
</xsl:call-template>
</table>
</xsl:template>
<xsl:template name="make-columns">
<xsl:param name="nodelist"/>
<xsl:param name="columns-number" select="3"/>
<tr>
<xsl:apply-templates select="$nodelist[
not(position() > $columns-number)
]"/>
<xsl:if test="count($nodelist) < $columns-number">
<xsl:call-template name="empty-cells">
<xsl:with-param name="finish"
select="$columns-number - count($nodelist)"/>
</xsl:call-template>
</xsl:if>
</tr>
<!-- If some nodes are left, recursively call current
template, passing only nodes that are left -->
<xsl:if test="count($nodelist) > $columns-number">
<xsl:call-template name="make-columns">
<xsl:with-param name="nodelist" select="$nodelist[
position() > $columns-number
]"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template match="item">
<td>
<xsl:apply-templates/>
</td>
</xsl:template>
<xsl:template name="empty-cells">
<xsl:param name="finish"/>
<td/>
<xsl:if test="not($finish = 1)">
<xsl:call-template name="empty-cells">
<xsl:with-param name="finish" select="$finish - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
我已经尝试在各种应用程序模板中插入命令,但不起作用。
想法?从评论
杰夫
更新
我想输出multicolum表 3列,其中的条目按字母顺序排列的 垂直
谢谢!这很好用! – 2011-04-05 00:10:41
@ Jeffrey-Hersh:在所以你应该接受两个答案中的一个 - @Alejandro和我都提供了正确和很好的答案。要接受答案,请点击旁边的绿色复选标记。 – 2011-04-05 01:50:18