XQuery - 在单个节点下包含元素序列

XQuery - Enclosing sequence of elements under a single node

我将 xquery 与 BaseX 结合使用,以尝试以我想要的格式从 JMeter 测试用例(.jmx 文件)中检索信息。
这是我实际上 运行 (在 BaseX GUI 内)的代码:

let $rlist := db:list("JMeter")
for $resource in $rlist
let $rcontent := db:open("JMeter", $resource)
let $ret :=
  <HttpRequest>
  {
    for $item in $rcontent/jmeterTestPlan//HTTPSamplerProxy
    return
      (<method>
      {
        $item/stringProp[attribute()/string() = "HTTPSampler.method"]/text()
      }
      </method>,
      <path>
      {
        let $parse := $item/stringProp[attribute()/string() = "HTTPSampler.path"]/text()
        let $parse := fn:replace($parse, "\?[^/]*", "")
        let $parse := fn:replace($parse, "$[^/]*", "${}")
        let $parse := fn:replace($parse, "[0-9]+", "${}")
        return $parse
      }
      </path>,
      <resource>
      {
        $resource
      }
      </resource>)
  }
  </HttpRequest>

return
<HttpRequests>
{
  $ret
}
</HttpRequests>

结果 xml 如下所示:

<HttpRequests>
  <HttpRequest>
    <method>POST</method>
    <path>/config</path>
    <resource>CentralConfiguration/Requests/addConfiguration.jmx</resource>
  </HttpRequest>
</HttpRequests>
<HttpRequests>
  <HttpRequest>
    <method>POST</method>
    <path>/propertyType</path>
    <resource>CentralConfiguration/Requests/addPropertyType.jmx</resource>
  </HttpRequest>
</HttpRequests>
...

这是我期望的结果:

<HttpRequests>
  <HttpRequest>
    <method>POST</method>
    <path>/config</path>
    <resource>CentralConfiguration/Requests/addConfiguration.jmx</resource>
  </HttpRequest>
  <HttpRequest>
    <method>POST</method>
    <path>/propertyType</path>
    <resource>CentralConfiguration/Requests/addPropertyType.jmx</resource>
  </HttpRequest>
  ...
</HttpRequests>

我非常感谢帮助格式化我的 xquery 以获得预期的结果,谢谢

通过将外部 for 循环放在第一个标签内解决了问题。