In the Fibonacci series, all digits except 1st and 2 are the sum of the first two digits, for example, 13...
XSLT (XSLT is a language for transforming XML documents into XHTML documents or to other XML documents) is a language for XML Conversion. There are some basic process controls in XSLT, such as <XSL: If> <XSL: Choose> <XSL: When> <XSL: otherwise>.
We know that to implement the Fibonacci series, we can call the series cyclically or recursively. The following describes how to use XSLT to output the Fibonacci series and obtain the nth value of the Fibonacci series. (It should be noted that because the number of the Fibonacci series is growing very fast, N should be as small as possible)
1. output the Fibonacci series
<? XML version = "1.0" encoding = "UTF-8"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: template match = "/">
<XSL: Call-Template Name = "repeat">
<XSL: With-Param name = "times" select = "5"/>
</XSL: Call-template>
</XSL: Template>
<XSL: Template Name = "repeat">
<XSL: Param name = "times" select = "0"/>
<XSL: Param name = "f1" select = "1"/>
<XSL: Param name = "F2" select = "1"/>
<XSL: If test = "$ times & gt 0">
<XSL: value-of select = "$ F1"/>
<XSL: Text>, </XSL: Text>
<XSL: value-of select = "$ F2"/>
<XSL: Text>, </XSL: Text>
<XSL: Call-Template Name = "repeat">
<XSL: With-Param name = "times" select = "$ times-1"/>
<XSL: With-Param name = "f1" select = "$ F1 + $ F2"/>
<XSL: With-Param name = "F2" select = "$ F2 + $ F1 + $ F2"/>
</XSL: Call-template>
</XSL: If>
</XSL: Template>
</XSL: stylesheet>
2. The value of item n in the Fibonacci series
<? XML version = "1.0" encoding = "UTF-8"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: template match = "/">
<XSL: Call-Template Name = "Fibonacci">
<XSL: With-Param name = "N" select = "$ N"/>
</XSL: Call-template>
</XSL: Template>
<XSL: Template Name = "Fibonacci">
<XSL: Param name = "N"/>
<XSL: Choose>
<XSL: When test = "$ N & lt; = 0">
<XSL: Text> 0 </XSL: Text>
</XSL: When>
<XSL: When test = "$ n = 1">
<XSL: Text> 1 </XSL: Text>
</XSL: When>
<XSL: otherwise>
<XSL: Call-Template Name = "fiboloop">
<XSL: With-Param name = "fn1" select = "1"/>
<XSL: With-Param name = "FN2" select = "0"/>
<XSL: With-Param name = "remains" select = "$ n-2"/>
</XSL: Call-template>
</XSL: otherwise>
</XSL: Choose>
</XSL: Template>
<XSL: Template Name = "fiboloop">
<XSL: Param name = "fn1"/>
<XSL: Param name = "FN2"/>
<XSL: Param name = "remains"/>
<XSL: variable name = "current" select = "$ fn1 + $ FN2"/>
<XSL: Choose>
<XSL: When test = "$ remains = 0">
<XSL: value-of select = "$ current"/>
</XSL: When>
<XSL: otherwise>
<XSL: Call-Template Name = "fiboloop">
<XSL: With-Param name = "fn1" select = "$ current"/>
<XSL: With-Param name = "FN2" select = "$ fn1"/>
<XSL: With-Param name = "remains" select = "$ remains-1"/>
</XSL: Call-template>
</XSL: otherwise>
</XSL: Choose>
</XSL: Template>
</XSL: stylesheet>
(Note: The above code may come from the network. This is the code I found on my computer. Haha)