用于XQuery嵌套循环的AutoIncremental auxiliar index var [英] Autoincremental auxiliar index var for XQuery nested loops

查看:331
本文介绍了用于XQuery嵌套循环的AutoIncremental auxiliar index var的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在vars中保存迭代次数,但正如你所知,xquery变量是不可变的



这里有一个特殊的语法,比如

$(bb

pre $ )$($ films)$ / $ / $ film $我} {数据($膜/ @标题)}< /膜>

我的问题是,当循环在另一个循环内时,如何保持绝对迭代的值。 $(b)

$ $ $ $ $ $ $ $ $ $ $ $ $ $在$($ films)'/ films / film
$ for $ goofs $ j $ in $ film / goofs / goof
return ** total_absolute_number_goof **

I意思是我不需要

pre $ code i = 1 j = 1,2,3 i = 1 j = 1,2,3
i = 2 j = 1,2,3 ... but i = 2 j = 4,5,6

是否有任何简单的方法来实现在xquery中?



编辑:相当于Java的

  int j = 0; (; some_external_condition;)
for(; some_external_condition; j ++){}
// j将打印总迭代次数

$ b $ $ p




$($ films)$ / $ / $ $ $ $ $ $ $ $ $ $在$电影/ goofs / goof
$ $ k
return $ k

它已被添加到一些XQuery处理器中,例如Saxon -EE 9.4。

在XQuery 1.0中,我认为你需要两遍:先创建电影列表,然后给它们编号。

I´m trying to hold the iteration number in vars, but as you know, xQuery vars are immutable

There´s an special syntax like

for $film at $i in doc('films.xml')/films/film
return <film>{$i}.{data($film/@title)}</film>

My problem is, how to hold the value of the absolute iteration when a loop is inside another loop.

for $film at $i in doc('films.xml')/films/film
for $goofs at $j in $film/goofs/goof
return **total_absolute_number_goof** 

I mean I dont need

i=1 j=1,2,3            i=1 j=1,2,3
i=2 j=1,2,3...  but    i=2 j=4,5,6

Is there any easy way to achieve that in xquery?

EDIT: java equivalent

int j = 0;
for (;some_external_condition;) 
   for (;some_external_condition;j++) {}
//j would print number of total iterations

解决方案

There's a feature in XQuery 3.0 to do this:

for $film at $i in doc('films.xml')/films/film
for $goofs at $j in $film/goofs/goof
count $k
return $k

It's already been added to some XQuery processors, for example Saxon-EE 9.4.

In XQuery 1.0 I think you would need two passes: first create the list of films, then number them.

这篇关于用于XQuery嵌套循环的AutoIncremental auxiliar index var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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