Add ordinal number to each item when using Xsl:for-each in XSL

Source: Internet
Author: User
Tags add format cdata xsl
For-each is often used to iterate through a set of nodes in XML, but it is often necessary to add an ordinal number to do so: <xsl:template match= "book" ><xsl:for-each select= "authors/" Author ">
<xsl:number value= " position ()"/><xsl:value-of select= "Name"/></xsl:for-each></xsl:template> of course, if you're not satisfied, you want to add "." After the numbers. You can do this: <xsl:number value= " position ()" format= "1."/>Even, you can use the picture to express 1\2\3 and so on: <xsl:element name= "img" >
<xsl:attribute name= "src" >images/n <xsl:number value= "position ()" format= "1"/>.gif</xsl:attribute>
<xsl:attribute name= "Border" >0</xsl:attribute>
</xsl:element> Note: You have a file like this in the Images folder: N1.gif,n2.gif,n3.gif ... Let's say we have XML as follows:
<Book>
<ID>125353-8993-3737</ID>
<ISBN>22222</ISBN>
<Title> Communism will win </Title>
<Authors>
<Author>
<name><! [cdata[bill&hoele]]></name>
<ID>12</ID>
</Author>
<Author>
<name><! [cdata[eylor]]></name>
<ID>1</ID>
</Author>
</Authors>
</Book>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.