【问题标题】:Why is this Xquery expression returning a null value?为什么这个 Xquery 表达式返回一个空值?
【发布时间】:2018-11-14 23:59:55
【问题描述】:

我想获得一个属性的最大值。我有以下声明:

让 $posts := doc("Posts.xml")/posts/row[./@OwnerUserId = $user/@Id]

让 $maxScore := fn:max(xs:integer($posts/row/@Score))

当我想返回 maxScore 时,它​​显示为一个空值。进一步修改后,以下内容:

返回 $posts/row/@Score

即使我知道每一行都有一个“分数”属性,也显示为空

我已经为此奋斗了一个多小时,感谢任何帮助

【问题讨论】:

    标签: xpath xquery


    【解决方案1】:

    您正在选择满足谓词条件的row 元素。因此,$posts 变量将具有一系列 row 元素。

    如果您想从$posts 变量中的每个row 元素中选择@Score,您的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))
    

    【讨论】:

      猜你喜欢
      • 2022-12-03
      • 2014-04-21
      • 2014-03-31
      • 1970-01-01
      • 2018-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多