Use XSLT to cycle different subnodes of the same xml Node

Source: Internet
Author: User
Tags month name xsl xslt
When you encounter XML files similar to the following, You need to place the different months of each year under the nodes of the year. If you use the C # programming language, it is easy to implement, because there are not many XSLT files, it also took me a bit of thought. <Rows>
<Row year = "2004" month = "2"/>
<Row year = "2004" month = "5"/>
<Row year = "2005" month = "2"/>
<Row year = "2004" month = "7"/>
<Row year = "2005" month = "4"/>
<Row year = "2005" month = "8"/>
</Rows>

The idea was to define a variable to record loops, but the assignment of the variable is always not executable. It took me more than an hour to complete the process and found that it was very simple and not as complicated as the implementation of other programming languages. It is easy for users who need it. <XSL: template match = "row" mode = "month">
<Month name = "{@ month}" imageindex = "28" link = ""/>
</XSL: Template>
<XSL: template match = "row">
<XSL: variable name = "POS" select = "position ()-1"/>
<XSL: If test = "$ Pos = 0 or ../row [$ POS]/@ year! = @ Year ">
<Year name = "{@ Year}" imageindex = "26">
<XSL: Apply-templates select = "../row [@ year = Current ()/@ year]" mode = "month"/>
</Year>
</XSL: If>
</XSL: Template>

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.