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!