如何让BaseX在嵌套XQuery中返回多个元素?

如何让BaseX在嵌套XQuery中返回多个元素?,xquery,basex,Xquery,Basex,BaseX正在抱怨我的嵌套查询。我不明白为什么它不能像第一次查询那样返回多行。错误显示为“Expecting},found>”,它所指的是trips下名称后的。如果}在id的右括号之后,它就可以正常工作,但显然,这不是我想要的。以下是查询: for $u in doc("export.xml")/database/USERS/tuple return <user> <login>{$u/USERNAME/text()}</login>

BaseX正在抱怨我的嵌套查询。我不明白为什么它不能像第一次查询那样返回多行。错误显示为“Expecting},found>”,它所指的
是trips下名称后的
。如果
}
在id的右括号之后,它就可以正常工作,但显然,这不是我想要的。以下是查询:

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>
用于文档中的$u(“export.xml”)/database/USERS/tuple
返回
{$u/USERNAME/text()}
{doc中的$t(“export.xml”)/database/TRIPS/tuple
其中$t/ADMIN/text()=$u/USERNAME/text()
返回
{$t/ID/text()}
{$t/NAME/text()}(:错误在这里,与:)
{$t/FEATURE/text()}
{$t/PRIVACY/text())
}

如果您想
返回多个项目,您需要将它们封装在序列
($item1,$item2,$itemn)
。在您的情况下:

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>
)

如果要
返回
多个项目,则需要将它们封装在一个序列中
($item1,$item2,$itemn)

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>
)