[xsl] Re: passing intermediate result while recursively building nodeset

 Subject: [xsl] Re: passing intermediate result while recursively building nodeset From: Dimitre Novatchev Date: Fri, 3 May 2002 08:05:46 -0700 (PDT)
```> I have question which is a variation of a previous question I had ...
> I'd like to recursively build up a nodeset, and I'd like to pass the
> intermediate result on with each recursive call.
>
> For example, if the template is passed the nodeset:
>     <a i=1/><a i=2/>
> and it creates the node:
>     <a i=3/>
> then I'd like to the template to recursively call itself passing the
> nodeset:
>     <a i=1/><a i=2/><a i=3/>
>
> Is this possible/reasonable/efficient?
>
> I was looking at the union operator, but it appears that there is no
> guarantee about the order of the elements in the resulting set and I
> would like to keep them ordered.  If 1.1 can't handle this, will it
> be something that 2.0 will be able to do?

Hi Paul,

Maybe you're not aware that you're describing the foldl or foldr
function, both forming the foundation of the FXSL library.

These two functions accept as parameters not only a list, but also a
function of two arguments to be performed on the temporary result and
the current element of the list (also sum initial value, with which to
start the function computation the first element of the list).

Almost every primitive recursive list-processing can be expressed by
any one of these two functions. For example:

sum xs = foldl (+) 0 xs

where (+) is the function that adds two numbers, computes the sum of
all the elements of the list xs.

append as bs = foldr (:) bs as

where (:) is the function that pre-pends an element at the start of a
list, appends the list bs to the list as

It seems to me that you want a combination of the above two functions.

Just remember: regardless of how many times you'll have to try to
repeat the awkward and difficult exercise of building up such a
recursive template from scratch, you're much better off just re-using
foldl or foldr.

These two functions have their analogues also on trees (also
implemented in FXSL).

Cheers,
Dimitre Novatchev.

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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

```