Subject: Re: [xsl] Functional Programming: How do I convert an xsl:for-each loop into a functional style? From: David Carlisle <davidc@xxxxxxxxx> Date: Thu, 21 Jan 2010 12:53:22 +0000 |
Hi Folks,
My question is about writing XSLT in a functional programming style.
My understanding is that a litmus test for whether a program is written in a functional style is whether it can be executed in any order.
Consider this problem: convert a sequence of N numbers into a cumulative sequence, in which each number is the sum of the previous numbers.
Here is a loop that solves the problem:
<xsl:for-each select="Number"> <xsl:value-of select="sum((., preceding-sibling::Number))" /> </xsl:for-each>
Can this code be executed in any order?
Suppose the loop is unraveled into a series of<xsl:value-of> statements. If those statements are evaluated in arbitrary order then the output would not be in the desired sequence. Thus, I conclude, this loop is not written in a functional style. Do you agree?
How would the problem be solved in a functional style?
________________________________________________________________________ The Numerical Algorithms Group Ltd is a company registered in England and Wales with company number 1249803. The registered office is: Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Functional Programming: How d, Costello, Roger L. | Thread | RE: [xsl] Functional Programming: H, Costello, Roger L. |
[xsl] Functional Programming: How d, Costello, Roger L. | Date | Re: [xsl] Functional Programming: H, Andrew Welch |
Month |