xsl-list
[Top] [All Lists]

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

2010-01-21 10:04:20

Thanks everyone for your responses. They have been very enlightening.

However, I am struggling to characterize what "functional programming" means. 
How will I recognize that one XSLT program is written in a functional style 
while another is not?

Let's take an example. Suppose I want to execute Statement 1 if Number is 
greater than 20, and Statement 2 if Number is greater than 10.

Here's one way to implement this:

<xsl:choose>
    <xsl:when test="Number gt 20">
        Statement 1
    </xsl:when>
    <xsl:when test="Number gt 10">
        Statement 2
    </xsl:when>
</xsl:choose>

Suppose Number has the value 25. If the two xsl:when tests can be executed in 
any order, then Statement 2 could be executed, which is not what I desire. 
Thus, I conclude, this xsl:choose is not written in a functional style. Do you 
agree?

Now, let me recast the implementation:

<xsl:choose>
    <xsl:when test="Number gt 20">
        Statement 1
    </xsl:when>
    <xsl:when test="(Number gt 10) and (Number le 20)">
        Statement 2
    </xsl:when>
</xsl:choose>

Now I get the desired results no matter what order the xsl:when tests are 
executed. Thus, I conclude, this xsl:choose is written in a functional style. 
Do you agree?

/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>
--~--