每个字母创建 windows 个结果

Create windows of results per alphabet

我的 XML 文件是 here

我想通过以下方式按字母顺序获取所有电影片名的结果:

<window>
<title>Alpha</title>
<title>Abel</title>
<window>
<title><babylon</title>
...
<window>
...
<window>
...

我在以下代码中使用翻滚功能:

for tumbling window $w in db:open("movies","movies.xml")/movies/movie/title
    start at $s when fn:true()
    only end at $e when not starts-with($e,substring($s, 1, 1))
return <window>{ $w/../title }</window>

基本上,我试图提取每个单词的第一个字符并将它们组合在一起。

但是,它说 FLWOR 表达式不完整。

在这里分组更合适:

for $title in //title
  order by $title
  group by $g := substring($title, 1,1)
return element { $g } {
  $title
}

当你真的想使用翻滚时,你可以使用 start 和 next 变量来创建组:

for tumbling window $w in //title
  start $first when true()
  end next $next when substring($first, 1,1) != substring($next,1,1)
return <window>{ $w }</window>