首页 > 开发 > Xml > 正文

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

2020-07-10 12:40:42
字体:
来源:转载
供稿:网友

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()&lt;Rows]"/>
</tr>
</xsl:for-each>
</table>
</xsl:template>

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

</xsl:stylesheet>

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表