XQuery 中是否有 CONNECT BY PRIOR 等效项?

Is there a CONNECT BY PRIOR equivalent in XQuery?

我正在使用支持 XQuery 3.0 的 BaseX。

假设我有一个这样的数据集,按 <start> 的值排序:

<element>
 <start>1</start>
 <end>2</end>
</element>
<element>
 <start>2</start>
 <end>4</end>
</element>
<element>
 <start>5</start>
 <end>6</end>
</element>

我想通过结束值和起始值连接这些元素,并将连接元素组合在一起:

<block>
  <start>1</start>
  <end>4</end>
</block>
<block>
  <start>5</start>
  <end>6</end>
</block>

在 Oracle 中,我们可以用 CONNECT BY PRIOR 做这样的事情。我们如何在 XQuery 中做到这一点?

您可以使用翻滚 window 来实现此行为,这样您就可以根据元素范围内的条件进行分组。滑动和翻滚windows需要XQuery 3.0,BaseX支持。

let $items := (
  <element>
    <start>1</start>
    <end>2</end>
  </element>,
  <element>
    <start>2</start>
    <end>4</end>
  </element>,
  <element>
   <start>5</start>
   <end>6</end>
  </element>
)
for tumbling window $window in $items
  start $start when fn:true()
  only end $end next $next when not(
  $end/end eq $next/start
)
return <block>{
  $start/start,
  $end/end
}</block>