经常用for-each来循环读取XML中的某个节点集,但常常需要加上序号
这样来做:
1<xsl:template match="Book">
2<xsl:for-each select="Authors/Author">
3<xsl:number value=" **position()** "></xsl:number>
4<xsl:value-of select="Name"></xsl:value-of>
5</xsl:for-each>
6</xsl:template>
当然,如果你不满意,想在数字后面加上"."可以这样:
1<xsl:number format="1." value=" **position()** "></xsl:number>
甚至,你可以用用图片表示1\2\3等:
1<xsl:element name="img">
2<xsl:attribute name="src">images/n ** <xsl:number format="1" value="position()"></xsl:number> ** .gif</xsl:attribute>
3<xsl:attribute name="border">0</xsl:attribute>
4</xsl:element>
注意:你在images文件夹下腰有类似这样的文件:n1.gif,n2.gif,n3.gif ... ...
假设我们XML如下:
1<book>
2<id>125353-8993-3737</id>
3<isbn>22222</isbn>
4<title>共产主义一定能胜利</title>
5<authors>
6<author>
7<name><![CDATA[Bill&Hoele]]></name>
8<id>12</id>
9</author>
10<author>
11<name><![CDATA[Eylor]]></name>
12<id>1</id>
13</author>
14</authors>
15</book>