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

时间:2016-04-13 03:41:17

标签: xml xquery basex xquery-3.0

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

         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)

但此刻,它会继续打印值,直到循环完成。如何只显示一次这些值?

1 个答案:

答案 0 :(得分:0)

不清楚正确的输出应该是什么,也许您只想使用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)