您的位置:首页 > Web前端 > HTML

XSL中实现HTML的表格自动换行

2005-10-23 15:04 639 查看
xml数据如:
<root>
<movie>1</movie>
<movie>2</movie>
<movie>3</movie>
<movie>4</movie>
<movie>5</movie>
<movie>6</movie>
<movie>7</movie>
<movie>8</movie>
<movie>9</movie>
<movie>10</movie>
<movie>11</movie>
<movie>12</movie>
</root>

要达到的效果:
1 2 3 4 5
6 7 8 9 10
11 12

XSL代码:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="Rows">5</xsl:variable>

<xsl:template match="//root">
<table>
<xsl:for-each select="movie[position() mod $Rows=1]">
<tr>
<xsl:apply-templates select=".|following-sibling::*[position()<$Rows]"/>
</tr>
</xsl:for-each>
</table>
</xsl:template>

<xsl:template match="movie">
<td>
<xsl:value-of select="."/>
</td>
</xsl:template>

</xsl:stylesheet>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: