如何读取与xQuery几个类似的节点?



假设我有一个结构如下的XML:

<book>
<title>My car is red</title>
<author>Jhon Doe</author>
<date>05-21-2021</date>
<illustration>
<name>front.jpg</name>
</illustration>
<illustration>
<name>back.jpg</name>
</illustration>
</book>

节点重复多次。使用xQuery,我可以读取所有节点:

for $book in /book
let $title := $book/title
let $author := $book/author
return
....

但是我想从XML文件中提取两个插图的名称。

我尝试使用以下代码:

for $illustration in $book/illustration
let $nombre := $illustration/name

但只读取最后一个节点的名称

我怎么能做到呢?

感谢

您可以为插图添加嵌套循环。

for $book in /book
let $title := $book/title
let $author := $book/author
for $illustration in $book/illustration
let $nombre := $illustration/name
return ...

最新更新