Re: [xsl] Functional programming in XSLT (revised)

Subject: Re: [xsl] Functional programming in XSLT (revised)
From: "David Rosenborg" <david.rosenborg@xxxxxxxxxx>
Date: Fri, 16 Mar 2001 11:54:31 +0100
Hi Alexey,

> <fxsl:function name="qname">
>   <!-- parameters -->
>   <!-- local variables and functions -->
>   <fxsl:return ...>
> </fxsl:function>
> 

I think you are working in all the right directions. However, the function definition part looks
very close to v0.2 of FXPath (http://www.pantor.com/fxpath02/). And I think there
were good reasons for the changes I made in v0.3 (http://www.pantor.com/fxpath/). Since you have
already decided to add new syntax to XPath, why not go all the way as in FXPath? In fact, why not
try and base your design on FXPath?

Simple outline:

* Allow fx:define and fx:template-function where you allow fxsl:function, with the same scoping rules.
* Add fx:call and fx:function extension functions (fx:function similar to fxsl:lambda, the word lambda is nice
  for historical reasons but I think function is more in line with XPath terminology)
* Add the non terminal FunctionDefinition to the Expr production.
* Maybe remove the special 'reduce' syntax. It can now be implemented as a function, though
  I would personally keep it for convenience.


> 3. Conditional operator in XPath
> --------------------------------
> 
> The conditional operator is added to XPath. The proposed syntax is
> 
> if TEST then CONSEQUENT else ATERNATE
> 
> where "if", "then" and "else" are "reserved words", and "TEST",
> "CONSEQUENT" and "ALTERNATE" are XPath expressions.
> 

You might consider requiring parenthesis around the consequent and alternate
expr as in FXPath. The reason is to get a more intuitive behaviour
in situations where you want to select the root node in the consequent like:

if $test then / else /something

would become

if ($test) then (/) else (/something)

also, this kind of syntax follows the pattern of other special forms/keywords in XPath.
 
> 4. Total cost
> -------------
> 
> Following is the total cost of this proposal (in terms of added
> features):
> 
> 1. Extension XSLT instructions:   1
> 2. Other XSLT extension elements: 1
> 3. Extension XPath functions:     2
> 4. Extension XPath data types:    1
> 5. Extensions in XPath syntax:    1
> -----------------------------------
> Total of added features:          6

Well, this cost doesn't say that much from an implementors point of view. Introducing locally scoped
functions and closures into current XSLT implementations is a rather intrusive thing. I'm not saying it's
particulary hard, just that it cannot be layered nicely on top of them.

Cheers,

</David>

David Rosenborg
Pantor Engineering AB



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread