Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath 为什么这个Xquery表达式返回空值?_Xpath_Xquery - Fatal编程技术网

Xpath 为什么这个Xquery表达式返回空值?

Xpath 为什么这个Xquery表达式返回空值?,xpath,xquery,Xpath,Xquery,我想获取属性的最大值。我有以下声明: 让$posts:=doc(“posts.xml”)/posts/row[./@OwnerUserId=$user/@Id] 设$maxScore:=fn:max(xs:integer($posts/row/@Score)) 当我想返回maxScore时,它显示为空值。在进一步修补后,将执行以下操作: 返回$posts/行/@Score 也显示为空,尽管我知道每行都有一个“Score”属性 我已经为此争论了一个多小时,非常感谢您的帮助您正在选择符合谓词标准的行

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

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

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

当我想返回maxScore时,它显示为空值。在进一步修补后,将执行以下操作:

返回$posts/行/@Score

也显示为空,尽管我知道每行都有一个“Score”属性


我已经为此争论了一个多小时,非常感谢您的帮助

您正在选择符合谓词标准的
元素。因此,
$posts
变量将有一系列
元素

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