gpt4 book ai didi

xpath - 动态排序 xquery 结果

转载 作者:行者123 更新时间:2023-12-03 17:03:12 32 4
gpt4 key购买 nike

我想根据 xpath 值动态使用升序或降序选项。

let $order := "ascending"
for $aRslt in ("1","2","3","4")
order by ($aRslt)
if($order eq "ascending") then ascending else descending
return $aRslt

使用这个抛出错误。

我们可以为整个“for”语句设置 if 条件。但是当我们在哪里有更多条件时;订购;和很多语句作为返回,然后它看起来代码重复只是为了升序或降序。

是否有任何选项可以在不使用整个“for”的条件的情况下使用。

最佳答案

每当我不得不动态订购时,这对我来说最有效。
它利用了多个订单规范。 ( http://www.w3.org/TR/xquery/#id-orderby-return ) 这有点不同,因为 order 修饰符是一个标记,而不是变量或表达式,因此很难使用。
这就是为什么你必须有两个 if 语句和空的 else 语句。

   let $order := "ascending"
for $aRslt in ("1","2","3","4")
order by
if($order eq "ascending") then $aRslt else() ascending,
if($order eq "descending") then $aRslt else () descending
return $aRslt

关于xpath - 动态排序 xquery 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33013477/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com