Recursive templates
An article that explains the use of recursive templates into a xsldocument to calculate factorial function:
http://www-106.ibm.com/developerworks/xml/library/x-xslrecur/.
An example of a recursive template; it's a simple text/plain document:
XslRecursiveTemplates_Example.zip