小编use*_*603的帖子

XQuery嵌套返回

我不太明白如何在返回中使用for嵌套.例如,给定

<book year="1994">
    <title>TCP/IP Illustrated</title>
    <author><last>Stevens</last><first>W.</first></author>
    <publisher>Addison-Wesley</publisher>
    <price>65.95</price>
</book>

<book year="1992">
    <title>Advanced Programming in the Unix environment</title>
    <author><last>Stevens</last><first>W.</first></author>
    <publisher>Addison-Wesley</publisher>
    <price>65.95</price>
</book>
Run Code Online (Sandbox Code Playgroud)

我想返回以下内容:

<price group = "65.95">
    <book year = "1994">
    <book year = "1992">
</price>
Run Code Online (Sandbox Code Playgroud)

但是根据我编写的代码,我收到错误Undefined variable $ b.我想知道是否有人能告诉我哪里出错了.谢谢!这是我的代码:

    for $p in distinct-values(//price)
return<price group ="{$p}">
(
  for $b in //book[price = $p]
    return <book year = "{$b/@year}"></book>
)
</price>
Run Code Online (Sandbox Code Playgroud)

xml xquery xml-parsing

3
推荐指数
1
解决办法
6303
查看次数

标签 统计

xml ×1

xml-parsing ×1

xquery ×1