[英]How do I get BaseX to return multiple elements in a nested XQuery?
BaseX is complaining about a nested query of mine. BaseX抱怨我的嵌套查询。 I do not understand why it cannot return multiple lines like it did in the first query.
我不明白为什么它不能像在第一个查询中那样返回多行。 The error says, "Expecting }, found >" and the
>
it is referring to is the >
after name under trips. 错误说:“期待},发现>”和
>
,它指的是>
下车次名之后。 It works fine if the }
is after the close-bracket for id, but obviously, that's not what I want. 如果
}
放在ID的右括号后面,则效果很好,但是显然,这不是我想要的。 Here is the query: 这是查询:
for $u in doc("export.xml")/database/USERS/tuple
return
<user>
<login>{$u/USERNAME/text()}</login>
<email></email>
<name></name>
<affiliation></affiliation>
<friend></friend>
<trip>
{for $t in doc("export.xml")/database/TRIPS/tuple
where $t/ADMIN/text() = $u/USERNAME/text()
return
<id> {$t/ID/text()} </id>
<name> {$t/NAME/text()} </name> (: Error is here with <name> :)
<feature> {$t/FEATURE/text()} </feature>
<privacyFlag> {$t/PRIVACY/text() </privacyFlag>)
}
</trip>
</user>
If you want to return
multiple items, you need to encapsulate them in a sequence ($item1, $item2, ..., $itemnN)
. 如果要
return
多个项目,则需要将它们封装在一个序列中($item1, $item2, ..., $itemnN)
。 In your case: 在您的情况下:
for $t in doc("export.xml")/database/TRIPS/tuple
where $t/ADMIN/text() = $u/USERNAME/text()
return (
<id> {$t/ID/text()} </id>,
<name> {$t/NAME/text()} </name>,
<feature> {$t/FEATURE/text()} </feature>,
<privacyFlag> {$t/PRIVACY/text() </privacyFlag>
)
But I'm unsure whether this will do what you expected, or if you actually want to create one element set per trip. 但是我不确定这是否会达到您的预期,或者您是否真的想为每次旅行创建一个元素集。 Then, you'd also have a single trip element for
result
and are not required to return a sequence (this is also what's the case in the outer flwor-loop, here the <user/>
element encapsulates to a single element): 然后,您还需要一个跳闸元素作为
result
,并且不需要返回序列(这也是外部flwor循环中的情况,这里<user/>
元素封装为一个元素):
for $t in doc("export.xml")/database/TRIPS/tuple
where $t/ADMIN/text() = $u/USERNAME/text()
return
<trip>
<id> {$t/ID/text()} </id>
<name> {$t/NAME/text()} </name>
<feature> {$t/FEATURE/text()} </feature>
<privacyFlag> {$t/PRIVACY/text() </privacyFlag>
</trip>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.