我想获得一个属性的最大值。我有以下声明:
让$ posts:= doc(“ Posts.xml”)/ posts / row [./@ OwnerUserId = $ user / @ Id]
让$ maxScore:= fn:max(xs:integer($ posts / row / @ Score))
当我想返回maxScore时,它显示为空值。进一步修改后,以下内容将:
返回$ posts / row / @ Score
即使我知道每一行都有一个“得分”属性,它也显示为空
我已经为此战斗了一个多小时,感谢您的帮助
最佳答案
您正在选择符合谓词条件的row
元素。因此,$posts
变量将具有一个row
元素序列。
如果要从@Score
变量的每个row
元素中选择$posts
,则XPath应该为:$posts/@Score
如果您将变量命名为$rows
,则将减少混乱。
或者,将XPath更改为实际选择posts
元素:
let $posts := doc("Posts.xml")/posts[row/@OwnerUserId = $user/@Id]
let $maxScore := fn:max(xs:integer($posts/row/@Score))