我正在使用XSLT。我知道内联函数表达式,有什么方法可以在xpath表达式中声明命名函数?因为我需要函数名称来实现递归调用。
在XSLT中,我只是建议使用xsl:function
这种方式,以便您的函数具有名称,并且可以在函数主体内部递归调用它。
至于纯XPath 3,Dimitre几年前在https://dnovatchev.wordpress.com/2012/10/15/recursion-with-anonymous-inline-functions-in-xpath-3-0-2/中探索了该路径。使用let
和更高阶的函数(不幸的是,Saxon 9 HE中不支持该功能),我认为他的代码使用的函数类型语法与最终规范不太一致,因此他的示例需要
let $f :=
function($n as xs:integer,
$f1 as function(xs:integer, function(*)) as xs:integer) as xs:integer {
if ($n eq 0)
then 1
else $n * $f1($n -1, $f1)
},
$F := function($n as xs:integer) as xs:integer {
$f($n, $f)
}
return $F(5)
可以缩短为
let $f :=
function($n as xs:integer,
$f1 as function(xs:integer, function(*)) as xs:integer) as xs:integer {
if ($n eq 0)
then 1
else $n * $f1($n -1, $f1)
},
$F := $f(?, $f)
return $F(5)
我认为给出了最新允许的语法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句