我想成功实现以下功能,如果您对其进行编码,它就可以工作:
declare function local:sort($collection as node()*, $filter as xs:SUBPATH?) as node()*{
for $element in $collection
order by
if ($filter) then ($element/$filter) (: OR SOME KIND OF fn:eval($filter) IF WE DEFINED $filter AS AN xs:string :)
else ($element/name()) (: Default :)
descending
return $element
};
它可以这样称呼:
for $element in local:sort(doc('data')/Data/*,'/@myAttr')
return $element
或者
for $element in local:sort(doc('data')/Data/*,'/subnode/subnode/name()')
return $element
或者
for $element in local:sort(doc('data')/Data/*,()) (: This is the default of function = own elment´s name :)
return $element
Mx 问题是通过子路径。要么我需要知道某种方式将相对 XPATH 作为参数和节点类型发送,要么我需要某种 eval 从 xs:string 传递到运行时有效代码
有什么帮助吗?