如何在 Xquery 结果中包含 position() 的值? [英] how to include the value of position() in an Xquery result?

查看:34
本文介绍了如何在 Xquery 结果中包含 position() 的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用滚动窗口,位置本身如何包含在结果中?

Without using tumbling windows, how is the position itself included in a result?

显然是$p"应该是索引"$items 中的每个 $item.话虽如此,迭代根本不能保证是连续的.

Obviously "$p" should be the "index" of each $item in $items. That being said, iteration isn't guaranteed to be sequential at all.

输出:

<result>
  <items>
    <item pos="$p">5</item>
    <item pos="$p">3</item>
    <item pos="$p">7</item>
    <item pos="$p">2</item>
    <item pos="$p">7</item>
    <item pos="$p">3</item>
  </items>
</result>

查询:

xquery version "3.1";

let $items := (5,3,7,2,7,3)
return
   <result>   
      <items>
      {
         for $item in $items[position()]
     let $p := position()
         return <item pos="$p">{$item}</item>
      }
      </items>
   </result>

查询改编自:

https://www.tutorialspoint.com/xquery/xquery_position.htm

推荐答案

您谈到使用滚动窗口,但您的查询不使用滚动窗口.

You talk of using tumbling windows, but your query doesn't use tumbling windows.

但是它确实使用了 FLWOR 表达式,并且 FLWOR 表达式不设置焦点,这意味着它们不设置 position() 的值.

It does however use FLWOR expressions, and FLWOR expressions don't set the focus, which means they don't set the value of position().

就你的例子而言,我认为你想要

For your example, I think you want either

for $item at $p in $items return <item pos="{$p}">{$item}</item>

或者更简单

$items ! <item pos="{position()}">{.}</item>

使用滚动窗口,您可以通过编写 start at $s end at $e 然后输出 $s 将变量绑定到窗口的开始和结束位置和 $e 在你的结果中.

With tumbling windows you can bind variables to the positions of the start and end of the window by writing start at $s end at $e and then output $s and $e in your result.

这篇关于如何在 Xquery 结果中包含 position() 的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆