Home:ALL Converter>Is XSLT a functional programming language?

Is XSLT a functional programming language?

Ask Time:2008-09-21T10:21:44         Author:Eric Weilnau

Json Formatter

Several questions about functional programming languages have got me thinking about whether XSLT is a functional programming language. If not, what features are missing? Has XSLT 2.0 shortened or closed the gap?

Author:Eric Weilnau,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/110031/is-xslt-a-functional-programming-language
Brian R. Bondy :

XSLT is declarative as opposed to stateful. \n\nAlthough XSLT is based on functional programming ideas, it is not a full functional programming language, it lacks the ability to treat functions as a first class data type. It has elements like lazy evaluation to reduce unneeded evaluation and also the absence of explicit loops.\n\nLike a functional language though, I would think that it can be nicely parallelized with automatic safe multi threading across several processors. \n\nFrom Wikipedia on XSLT:\n\n\n As a language, XSLT is influenced by\n functional languages, and by\n text-based pattern matching languages\n like SNOBOL and awk. Its most direct\n predecessor was DSSSL, a language that\n performed the same function for SGML\n that XSLT performs for XML. XSLT can\n also be considered as a template\n processor.\n\n\nHere is a great site on using XSLT as a functional language with the help of FXSL. FXSL is a library that implements support for higher-order functions.\n\nBecause of FXSL I don't think that XSLT has a need to be fully functional itself. Perhaps FXSL will be included as a W3C standard in the future, but I have no evidence of this. ",
2008-09-21T02:29:02
joegy :

I am sure you guys have found this link by now :-) http://fxsl.sourceforge.net/articles/FuncProg/Functional%20Programming.html .\n\nWell functions in XSLT are first class-citizens with some work arounds after all :-)",
2009-01-29T18:37:34
JohnnySoftware :

That is sort of how it feels when I am programming it. \n\nXSLT is entirely based on defining functions and applying them to selected events that come down the input stream.\n\nXSLT lets you set a variable. Functional programming does not allow functions to have side effects - and that is a biggie.\n\nStill, writing in XSLT, one has the same \"feel as working in an FP fashion. You are working with input - you are not changing it - to create output.\n\nThis is a very, very different programming model from that used when working with the DOM API. DOM does not separate input and output at all. You are handed a data structure - and you mangle it how you see fit - without hesitation, restriction, or remorse.\n\nSuffice it to say if you like FP and the principles behind it, you will probably feel comfortable working in it. Just like experience with event driven programming - and XML itself - will make you comfortable with it as well.\n\nIf your only experience is with top-down, non event driven programs - then XSLT will be very unfamiliar, alien landscape indeed. At least at first. Growing a little experience and then coming back to XSLT when XPath expressions and event-handling are really comfortable to you will pay off handsomely.",
2008-10-19T15:12:48
Ian P :

For the most part, what makes XSLT not a 100% functional programming language is it's inability to treat functions as a first-class data type.\n\nThere may be some others -- but that's the obvious answer.\n\nGood luck!",
2008-09-21T02:23:46
JeniT :

Saxon-SA has introduced some extension functions which make XSLT functional. You can use saxon:function() to create a function value (actually a {http://net.sf.saxon/java-type}net.sf.saxon.expr.UserFunctionCall value) which you then call with saxon:call().\n\nSaxon-B has similar functionality with the pairing of saxon:expression() and saxon:eval(). The difference is that saxon:expression() takes any XPath expression, and saxon:eval() evaluates it, whereas saxon:function() takes the name of a function which saxon:call() calls.",
2008-09-21T16:53:46
yy