我不太明白如何使用嵌套在返回中的 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>
我想返回以下内容:
<price group = "65.95">
<book year = "1994">
<book year = "1992">
</price>
但是使用我编写的代码,我收到错误未定义变量 $b。我想知道是否有人可以告诉我我哪里出错了。谢谢!这是我的代码:
for $p in distinct-values(//price)
return<price group ="{$p}">
(
for $b in //book[price = $p]
return <book year = "{$b/@year}"></book>
)
</price>