首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XSLT文件夹:函数列表?

XSLT文件夹:函数列表?
EN

Stack Overflow用户
提问于 2013-09-09 20:22:40
回答 2查看 274关注 0票数 3

由于我所做的一些遗留工作,我最近一直在学习如何在XSLT1.0中使用函数式编程结构。因此,我一直在学习有关FXSL的更多信息,并对foldl提出了一些问题。

代码语言:javascript
复制
 <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>

我的问题与vFunResult变量有关。我了解到它正在使用$pFunc模板创建一个“函数”应用程序,但是为什么$pFunc选择器,以及为什么模板调用中的arg0被设置为$pFunc[position > 0],是否期望您将中的多个“函数”传递给 foldl**?**

在我看到的所有函数编程示例中,参数f是在奇数中传递的,而不是以列表的形式传递的,ala Haskell部分函数定义:foldl f z (x:xs) = foldl f (f z x) xs

EN

回答 2

Stack Overflow用户

发布于 2013-09-12 03:58:21

我相信我是一个“可信和官方的”消息来源,因为我碰巧是FXSL :)的作者。

我的问题与vFunResult变量有关。我知道它正在用$pFunc模板创建一个“函数”应用程序,但是为什么[1]选择器,以及为什么arg0 in the template call being set to $pFuncposition > 0? Is it expected that you are passing more than one 'function' in$pFunctofoldl`?

首先,这是一个很好的观察。你是13年来第一个注意到这一点的人。

,这纯粹是历史原因,。当我在2001年写FXSL时,我还在学习Haskell和。

在某些问题中,折叠显然是解决方案,但是,我们指定的函数需要一个额外的参数。正如我所说的,我只是在编写这些函数,我还没有弄清楚如何实现部分应用程序(这是在四个月后通过引入curry()函数完成的。(见此处:函数。)这就是为什么我当时决定,在这种情况下,额外的参数可以作为列表的尾部传递,列表的第一项是foldl所期望的“正式”函数。

我确实注意到,fxsl.sourceforge.net/articles/FuncProg/2.html#List_processing上的所有示例在$pFunc中只传递一个模板.所以我最初的想法是,arg0一般都被$pFuncs忽略了?

这不是一个正确的结论。

请参阅此处:http://fxsl.sourceforge.net/articles/FuncProg/2.html如何实现minimum / maximum函数。他们期望以$arg0的形式传递一个实现<比较的附加函数。因此,这些函数是完全通用的,不依赖于列表中项的数据类型。

总之,正如我所说,问题中的观察反映了一个纯粹的历史事实。如果看一下FXSL2.0的代码,这个“特性”就完全消失了:http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/func-foldl.xsl?revision=1.3&view=markup

该函数本质上被定义为一个XPath 2.0单线行:

代码语言:javascript
复制
  <xsl:sequence select=
         "if (empty($pList))
              then 
                  $pA0
              else
                  f:foldl($pFunc, 
                          f:apply($pFunc, $pA0, $pList[1]), 
                          $pList[position() > 1]
                          )"/>

最后,感谢您对FXSL的兴趣。我建议您查看FXSL2.x(用于XSLT2.0),并阅读我2006年在极限标记语言会议上的论文:http://conferences.idealliance.org/extreme/html/2006/Novatchev01/EML2006Novatchev01.html

在XSLT2.0中,几乎可以完全使用XPath 2.0编写大部分FXSL函数,并将其作为一行程序编写。

当然,您还需要看到W3C XPath 3.0规范:http://www.w3.org/TR/xpath-30/#id-inline-func,其中高阶函数(HOFs)已经完全成为了语言的一部分。你也可能对我上个月在2013年Balisage会议上发表的论文感兴趣:“XPath 3.0中的编程”。这篇论文是:http://t.co/p3mdgoTdgj

然而,PPT演示文稿可能更有趣:https://t.co/i5xCTUObvp

票数 5
EN

Stack Overflow用户

发布于 2013-09-12 03:36:20

pFunc是一个列表,因此foldl可以应用本身需要额外参数的函数。附加参数pFuncposition() > 1通过arg0传递给pFunc1提供的函数。

例如,查看FXSL 最小值函数,该函数可以接受比较函数pCMPFun,然后它可以通过pFuncposition() > 1传递到foldl

代码语言:javascript
复制
     <xsl:template name = "minimum" >
         <xsl:param name = "pList" select = "/.." />
         <xsl:param name = "pCMPFun" select = "/.." />

         <xsl:variable name = "vdfCMPFun" 
                       select = "document('')/*/minimum-own-compare:*[1]" />

         <xsl:variable name = "vFoldFun" 
                       select = "document('')/*/minimum-pick-smaller:*[1]" />

         <xsl:if test = "$pList" >
             <xsl:variable name = "vCMPFun" 
                           select = "$pCMPFun | $vdfCMPFun[not($pCMPFun)]" />

             <xsl:variable name = "vFuncList" >
                 <xsl:copy-of select = "$vFoldFun" /> <!-- Pick Smaller --> 
                 <xsl:copy-of select = "$vCMPFun" /> <!-- Compare --> 
             </xsl:variable>

             <xsl:call-template name = "foldl" >
                 <xsl:with-param name = "pFunc" 
                                 select = "msxsl:node-set($vFuncList)/*" />
                 <xsl:with-param name = "pList" select = "$pList" />
                 <xsl:with-param name = "pA0" select = "$pList[1]" />
             </xsl:call-template>
         </xsl:if>
     </xsl:template>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18706414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档