I've been learning about using functional programming constructs in XSLT 1.0 lately, due to some legacy work I've been doing. So I've been learning more about FXSL, and have some questions about foldl.
<xsl:template name = "foldl" >
<xsl:param name = "pFunc" select = "/.." />
<xsl:param name = "pA0" />
<xsl:param name = "pList" select = "/.." />
<xsl:choose>
<xsl:when test = "not($pList)" >
<xsl:copy-of select = "$pA0" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name = "vFunResult" >
<xsl:apply-templates select = "$pFunc[1]" >
<xsl:with-param name = "arg0" select = "$pFunc[position() > 1]" />
<xsl:with-param name = "arg1" select = "$pA0" />
<xsl:with-param name = "arg2" select = "$pList[1]" />
</xsl:apply-templates>
</xsl:variable>
<xsl:call-template name = "foldl" >
<xsl:with-param name = "pFunc" select = "$pFunc" />
<xsl:with-param name = "pList" select = "$pList[position() > 1]" />
<xsl:with-param name = "pA0" select = "$vFunResult" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
My question has to do with the vFunResult
variable. I get that it is making a 'function' application with the $pFunc
template, but why the [1]
selector, and why is the arg0 in the template call being set to $pFunc[position > 0]
? Is it expected that you are passing more than one 'function' in $pFunc
to foldl
?
In all the functional-programming examples that I've seen, the parameter f is passed in singularly and not as a list, ala this Haskell partial function definition: foldl f z (x:xs) = foldl f (f z x) xs