The "Fibonacci series" implemented using XSLT"

Source: Internet
Author: User
Tags xsl xslt
Data source XML, Data. xml

<? XML version = "1.0" encoding = "gb2312" ?>
<? XML-stylesheet type = "text/XSL" href = "style. XSLT" ?>
< Root >
< Troot > 0 </ Troot >
< Troot > 1 </ Troot >
< Troot > 2 </ Troot >
< Troot > 3 </ Troot >
< Troot > 4 </ Troot >
< Troot > 5 </ Troot >
< Troot > 6 </ Troot >
< Troot > 7 </ Troot >
< Troot > 8 </ Troot >
< Troot > 9 </ Troot >
< Troot > 10 </ Troot >
< Troot > 11 </ Troot >
< Troot > 12 </ Troot >
< Troot > 13 </ Troot >
< Troot > 14 </ Troot >
< Troot > 15 </ Troot >
< Troot > 16 </ Troot >
< Troot > 17 </ Troot >
< Troot > 18 </ Troot >
< Troot > 19 </ Troot >
< Troot > 20 </ Troot >
</ Root >

The following is the implementation of XSLT, style. XSLT <? XML version = "1.0" encoding = "gb2312" ?>
< XSL: stylesheet Version = "1.0" Xmlns: XSL = "Http://www.w3.org/1999/XSL/Transform" >
< XSL: Output Method = "Html" Version = "4.0" Encoding = "Gb2312" />
< XSL: Template Match = "/" >
< Html >
< Head >
< Title > Fibonacci series in XSLT version </ Title >
< Style Type = "Text/CSS" >
< XSL: Comment > <! [CDATA [
Span
{
Font: 9pt;
Color: #999;
Display: List-item;
List-style: none;
}
]> </ XSL: Comment >
</ Style >
</ Head >
< Body >
< Span > Fibonacci series: </ Span >
< XSL: For-each Select = "Root/troot" >
< Span >
When N = < XSL: value- Select = "." Disable-output-escaping = "No" /> Result:
< XSL: Call-template Name = "Fun" >
< XSL: With-Param Name = "N" Select = "." />
</ XSL: Call-template >
</ Span >
</ XSL: For-each >
</ Body >
</ Html >
</ XSL: Template >
< XSL: Template Name = "Fun" >
< XSL: Param Name = "N" />
< XSL: Choose >
< XSL: When Test = "$ N & lt; = 1" >
< XSL: value- Select = "1" Disable-output-escaping = "No" />
</ XSL: When >
< XSL: otherwise >
< XSL: Variable Name = "Ni" >
< XSL: Call-template Name = "Fun" >
< XSL: With-Param Name = "N" Select = "$ N-1" />
</ XSL: Call-template >
</ XSL: Variable >
< XSL: Variable Name = "NII" >
< XSL: Call-template Name = "Fun" >
< XSL: With-Param Name = "N" Select = "$ N-2" />
</ XSL: Call-template >
</ XSL: Variable >
< XSL: value- Select = "Number ($ NII) + number ($ Ni )" />
</ XSL: otherwise >
</ XSL: Choose >
</ XSL: Template >
</ XSL: stylesheet >

The main purpose is to verify that the template in XSLT is recursive. It can also have a "Return Value" like a common function, through variable.
However, this variable is really a bit difficult. It can only be assigned once and cannot be changed again!

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.