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>