[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Is xsl:for-each "syntactic sugar"?


Subject: Re: [xsl] Is xsl:for-each "syntactic sugar"?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 07 May 2010 02:41:15 +0100

On 07/05/2010 00:02, Costello, Roger L. wrote:
> Hi Folks,
>
> 1. Everything that can be done using xsl:for-each can be done using a recursive function. (True or False)


anything that can be done on a computer can be done with a recursive function so clearly the statement is true, but not very informative.
More to the point, xsl:for-each is (if you want to view it that way) syntactic sugar for apply-templates in a unique mode, with a single template that matches all nodes.


>
> 2. There are things that can be done using a recursive function that cannot be done using xsl:for-each. (True or False)


the two things are not comparable. "recursive function" is an abstract concept not related to any particular programming language. "xsl:for-each" is a particular syntactic construct in xslt. You can not do anything with xsl:for-each on its own, its expressive power is just related to what you use in the body, which can of course include calling recursive functions.

>
> 3. xsl:for-each is syntactic sugar. (True or False)

As above, it can be seen as syntactic variation on apply-templates, however you have to work quite hard to get exactly the same behaviour with respect to variable scope.

>
> 4. Favor recursive functions over xsl:for-each. (True or False)

One might always expect that compilers have an easier job to optimise specific language constructs rather than using generic programming constructs which have notionally the same behaviour. Thus one would presumably expect to find that xsl:for-each is going to be pretty efficient.
>
> /Roger


David


Current Thread