xsl-list
[Top] [All Lists]

[xsl] Functional Programming: How do I convert an xsl:for-each loop into a functional style?

2010-01-21 06:38:42
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?

/Roger
--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--