Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
Until now it was believed that although XSLT is based on
functional programming ideas, it is not as yet a full functional
programming language, as it lacks the ability to treat functions as
a first-class data type. Based on numerous concrete XSLT
implementations of some of the major functional programming design
patterns, including some of the most generic list-processing and
tree-processing functions, this article provides ample proof that
XSLT is in fact a full-pledged functional programming language. The
presented code forms the base of a first XSLT functional
programming library. It is emphasized that a decision to include
higher-order functions support in XPath 2.0 will make functional
programming in XSLT even more straightforward, natural and
convenient.
XSLT has turned out to be very different from the typical
programming languages in use today. One question that's being asked
frequently is: "What kind of programming language is actually
XSLT?". Until now, the authoritative answer from some of the
best specialists was that XSLT is a declarative (as opposed to
imperative) but still not a functional programming (FP) language.
Michael Kay notes in his article "What kind of language is XSLT"
[3] :
"although XSLT is based on functional programming ideas, it is
not as yet a full functional programming language, as it lacks the
ability to treat functions as a first-class data type".
What has been done to bring XML and FP languages closer
together? One notable direction is to add XML support to some
well-known FP languages, such as the HaXML compiler and tools
written in Haskell
[6], the LambdaXML xml-based FP language and the XML
support in Erlang
[2].
However, nothing is seemingly being done in the other direction
-- to add functional programming capabilities to XSLT. The citation
in the start of this section reflects the unanimous, dominating
understanding of XSLT as a declarative-only programming language,
which does not belong to the family of FP languages, due to its
lack of support for higher order functions.
The purpose of this article is to demonstrate beyond any doubt
that XSLT is a functional programming language in its own
right. To achieve this goal, a reference XSLT implementation is
provided of major FP concepts and functions. This article closely
follows the contents and layout of John Hughes' article "Why
functional programming matters"
[1], in which some most typical and useful FP patterns and
functions are defined. This article provides an XSLT implementation
of most of the functions defined in
[1]. Therefore, the reader is encouraged to read
[1] either prior, or side-by-side with the current article.