For loop 如何使用Xquery增加循环?

For loop 如何使用Xquery增加循环?,for-loop,xquery,exist-db,For Loop,Xquery,Exist Db,如何使用xquery将循环从第十四个增加到第十四个。例如,我有一个循环: for $i in (0 to 150) return $i 我想把这个循环增加十四。输出: 14 28 42 56 70 etc. 我正在处理exist db。尝试以下操作: for $i in (0 to 150) return ($i+1)*14 试试这个: for $i in (0 to 150) return ($i+1)*14 最简单的方法(可能也是最容易阅读的方法)是使用模函数过滤序列,但这

如何使用xquery将循环从第十四个增加到第十四个。例如,我有一个循环:

for $i in (0 to 150)
return $i
我想把这个循环增加十四。输出:

14

28

42

56

70

etc.
我正在处理exist db。

尝试以下操作:

for $i in (0 to 150)
return ($i+1)*14
试试这个:

for $i in (0 to 150)
return ($i+1)*14

最简单的方法(可能也是最容易阅读的方法)是使用模函数过滤序列,但这有一个缺点,即所有150个值都必须构造:

(1 to 150)[. mod 14 = 0]
使用@prker使用的方法,您必须自己计算上限
idiv
是整数除法运算符

for $i in (1 to 150 idiv 14)
return $i * 14
使用XQuery 3.0,您还可以使用应用运算符
改为:

(1 to 150 idiv 14) ! (. * 14)
或者最后使用递归函数

declare function local:n-sequence($from as xs:integer, $to as xs:integer, $step as xs:integer) {
  if ($from > $to)
  then ()
  else ($from, local:n-sequence($from + $step, $to, $step))
};

local:n-sequence(1, 150, 14)

最简单的方法(可能也是最容易阅读的方法)是使用模函数过滤序列,但这有一个缺点,即所有150个值都必须构造:

(1 to 150)[. mod 14 = 0]
使用@prker使用的方法,您必须自己计算上限
idiv
是整数除法运算符

for $i in (1 to 150 idiv 14)
return $i * 14
使用XQuery 3.0,还可以使用应用操作符
改为:

(1 to 150 idiv 14) ! (. * 14)
或者最后使用递归函数

declare function local:n-sequence($from as xs:integer, $to as xs:integer, $step as xs:integer) {
  if ($from > $to)
  then ()
  else ($from, local:n-sequence($from + $step, $to, $step))
};

local:n-sequence(1, 150, 14)
或:对于(1到151)中的$i,返回$i*14;或者:对于(1到151)中的$i,返回$i*14