如何在 Xquery 中只显示一次变量?

How to display the variables only once in Xquery?

我试图同时显示三个不同的变量。 这是我试过的。

         let $totalmovies := count(//Movies/Movie)
         let $averagevariton:=(count(//Movies/Movie/secondtitles/OtherTitleName) + count(//Movies/Movie/Title) ) div $totalmovies

         for $m in //Movies/Movie
         let $year := (max($m/secondtitles/Year) - min($m/secondtitles/Year))+1

         order by $year descending

         return ($totalmovies,$averagevariton,$year)

但目前,它会一直打印值,直到 for 循环完成。我怎样才能只显示一次这些值?

不清楚正确的输出应该是什么,也许您只想使用 for 循环来填充 $year 变量,如下所示:

let $totalmovies := count(//Movies/Movie)
let $averagevariton:= (count(//Movies/Movie/secondtitles/OtherTitleName) + count(//Movies/Movie/Title) ) div $totalmovies
let $year := 
    for $m in //Movies/Movie
    let $diff := (max($m/secondtitles/Year) - min($m/secondtitles/Year))+1
    order by $diff descending
    return $diff
return ($totalmovies,$averagevariton,$year)