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>
博客展示了一段XML数据,包含多个movie元素。目标是将这些数据按每行5个元素的格式展示。通过一段XSL代码实现该效果,代码中定义了变量和模板,利用XSL的功能将XML数据转换为HTML表格形式输出。
12

被折叠的 条评论
为什么被折叠?



