[xsl] Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?

Subject: [xsl] Re: Re: lookup-table thoughts (was Re: matching multiple times, outputting once?
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Wed, 7 Nov 2001 03:44:29 -0800 (PST)
Tom Myers wrote:


> And that seems to handle the problem...unless I'm missing something.
> It's interesting, I think, that even when filled in, the accumulator
> pattern has no idea that the nodelist is a list of attributes...and
> info about the mapping of names is confined to the lookup table. Of
> course you can make it a little shorter and faster in various ways,
> e.g. by bringing the call-template that defines "recresult" into
> the one and only place $recresult is used, avoiding the copy-of.
> But mainly it's interesting that so little thought is required.
> And I'm wondering what I'm missing this time. Oh well, back to
> data bases.

Tom, you're not missing anything, except maybe that there are ways in XSLT to fill
this general accumulator pattern by passing functions as parameters. Yes, this is
possible in XSLT. Have you heard about the concept of "generic templates"?
If not, here's a link explaining the concept and giving some examples:


And the pattern you pointed out is called "fold" in Haskell.

Here's the XSLT implementation of the function foldl (fold from left to right, foldr
is fold from right to left), which in Haskell is defined as:

foldl f z [] = z

foldl f z (x:xs) = foldl f (f z x) xs

<xsl:template name="foldl">
<xsl:param name="pFunc" select="/.."/>
  <xsl:param name="pA0"/>
  <xsl:param name="pList" select="/.."/>

     <xsl:when test="not($pList)">
        <xsl:copy-of select="$pA0"/>
       <xsl:variable name="vFunResult">
          <xsl:apply-templates select="$pFunc[1]">
            <xsl:with-param name="arg0" select="$pFunc[position() > 1]"/>
            <xsl:with-param name="arg1" select="$pA0"/>
            <xsl:with-param name="arg2" select="$pList[1]"/>

       <xsl:call-template name="foldl">
          <xsl:with-param name="pFunc" select="$pFunc"/>
          <xsl:with-param name="pList" select="$pList[position() > 1]"/>
          <xsl:with-param name="pA0" select="$vFunResult"/>



This is just one code example from an article I'm about to finish in a couple of
days. I promise to send you the link to it as soon as possible when it is published.
I would also appreciate the help of anyone who'd be interested act as a reviewer.

In the meantime, I'd greatly appreciate it, if somebody could recommend where to
publish this article -- it has grown quite long since it contains many many examples
of XSLT implementations of major functional programming design patterns.

Dimitre Novatchev.

Do You Yahoo!?
Find a job, post your resume.

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

Current Thread