表达式中的xquery计数 [英] xquery count for expressions in a for expressions

查看:97
本文介绍了表达式中的xquery计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我该如何在父母不明的for表达式中计算for表达式.

question is how could i count the for expressions in a for expressions with unknow parent.

代码:

let $act :=(
<act time="1231">
     <data value="2">hello</data>
     <data value="2">hello</data>
     <data value="2">hello</data>
     <data value="2">hello</data>
     <data value="2">hello</data>
     <data value="2">hello</data>
</act>,
<act time="51292">
 <state>
     <data value="2">world</data>
     <data value="2">world</data>
     <data value="2">world</data>
     <data value="2">world</data>
     <data value="2">world</data>
 </state>
</act>,
<act time="41212">
 <state1>
    <state2>
     <data value="2">3</data>
     <data value="2">3</data>
     <data value="2">3</data>
     <data value="2">3</data>
     <data value="2">3</data>
    </state2>
 </state1>
</act>
)

for $data in $act
return
<act time ="{$data/@time}">
    {
    for $count at $cnt in $act//data
    where $count/.. is $data
    return
    <data value ="{$count}">{$cnt}</data>

    }
</act>

结果:

<act time="1231">
   <data value="hello">1</data>
   <data value="hello">2</data>
</act>
<act time="51292"/>
<act time="41212"/>

期望:

<act time="1231">
   <data value="hello">1</data>
   <data value="hello">2</data>
</act>,
<act time="51292">
   <data value="world">3</data>
   <data value="world">4</data>
</act>,
<act time="41212">
   <data value="3">5</data>
   <data value="3">6</data>
</act>

还链接到代码,该代码显示什么是结果以及我期望什么 https://xqueryfiddle.liberty-development.net/pPgCcoE/11

also link to the code what shows what is a result and what am i expecting https://xqueryfiddle.liberty-development.net/pPgCcoE/11

推荐答案

我认为您只是想更改where子句以使用where $count/ancestor::act is $data,即检查祖先act元素是否是绑定到的元素外部for表达式的$data变量.

I think you simply want to change the where clause to use where $count/ancestor::act is $data, i.e. to check whether the ancestor act element is the element bound to the $data variable of the outer for expression.

这篇关于表达式中的xquery计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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