Re: [xsl] [FXSL] Using document('') to get the high-level function (+ a little bug?)

Subject: Re: [xsl] [FXSL] Using document('') to get the high-level function (+ a little bug?)
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Sat, 24 Jun 2006 06:54:48 -0700
Hi Florent,

 There is no mailing list on the SF.net project page for
FXSL, but I think my question is on topic here (Dimitre,
could you please let me know if there is a more appropriate
place to discuss FXSL?).

There are three fora for the FXSL project:


FXSL Help
Help
Open Discussion

There's also a Developers forum, which is visible only project members.

I agree with Colin and would be glad to add you as a developer to the
FXSL project -- please, let me know.


 I noted that FXSL for XSLT 2.0 still uses in its test
scripts the following construct to pass the high-level
function to the FXSL templates:

   <myAdd:myAdd/>
   <xsl:template match="/">
     <xsl:variable name="vFun" select="document('')/*/myAdd:*[1]"/>
     <xsl:call-template name="zipWith">
       <xsl:with-param name="pFun" select="$vFun"/>
       ...

 So it requires to access to the XML rpresentation of the
script.  Is there any reason (other than historical) to not
use something like the following, which IMHO seems more
appropriate (at least in large scripts)?

   <xsl:template match="/">
     <xsl:variable name="vFun" as="element()">
       <myAdd:myAdd/>
     </xsl:variable>
     <xsl:call-template name="zipWith">
       <xsl:with-param name="pFun" select="$vFun"/>
       ...

You're right, the reason is historical.


What is more, do not use this template at all -- there is an
xsl:function named f:zipWith and it should be used with FXSL2.

The legacy templates are included in FXSL2 to ensure that old FXSL 1.x
code is still supported.

In fact in the test of f:zipWith(), an even better way is used to pass
the function-parameter (see the file testFunc-zipWith.xsl):

f:zipWith(f:add(), (/*/*)[position() &lt; 6], (/*/*)[position() > 5])

Here one doesn't manually provide/code a reference to a function that
adds its two arguments -- FXSL provides higher-order function wrappers
as f:add() above, which evaluate to the necessary reference. Also,
these wrappers are identically named as the referenced original F & O
function/operator (if we disregard the namespace), so in order to pass
the "+" operator as a parameter one simply writes
    "f:add()"

This will be presented and discussed in detail in my presentation at
the Extreme Markup Languages 2006 conference in August.


BTW, the zipWith template call itself recursively, passing the literal default value 'el' for the pElName parameter, instead of the actual value of this parameter, $pElName. I guess it is a bug?

   <xsl:call-template name="zipWith">
     ...
     <xsl:with-param name="pElName"
                     select="'el' (: not $pElName ? :)"/>
   </xsl:call-template>


Yes, this is a legacy of the FXSL 1.x code, which as I mentioned has been just copied into FXSL 2.0, but everyone is encouraged to use the new code, based on xsl:function. In the implementation of f:zipWith() the two parameter-lists are simply sequences, so there's no need to represent their items as elements and there is no parameter for the element name.

--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.

Current Thread