xquery for 循环问题
我有一个包含图书馆书籍的 xml。我想列出所有未借出的书。所以我的方法是获取所有书籍,如果书籍 ID 与已签出的书籍 ID 匹配,则不列出它,否则列出它。
在java或其他语言中,我会做一个双for循环并循环遍历元素是否有与xQuery类似的东西?
<book asin="0201100886" created="128135928" lastLookupTime="128135928">
<uuid>BA57A934-6CDC-11D9-830B-000393D3DE16</uuid>
<title>Compilers</title>
<authors>
<author>Alfred V. Aho</author>
<author>Ravi Sethi</author>
<author>Jeffrey D. Ullman</author>
</authors>
<publisher>Addison Wesley</publisher>
<published>1986-01-01</published>
<price>102.00</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<borrowers>
<borrower id="1">
<name> John Doe </name>
<phone> 555-1212 </phone>
<borrowed>
<book asin="0138613370"/>
<book asin="0122513363"/>
</borrowed>
</borrower>
</borrowers>
I have a xml containing books at a library. I want to list all the books that arent checked out. So m approach is to get all the books and if the book id matches a checked out book id do not list it, otherwise list it.
In java or another language I would do a double for loop and loop over the elements is there something similar with xQuery?
<book asin="0201100886" created="128135928" lastLookupTime="128135928">
<uuid>BA57A934-6CDC-11D9-830B-000393D3DE16</uuid>
<title>Compilers</title>
<authors>
<author>Alfred V. Aho</author>
<author>Ravi Sethi</author>
<author>Jeffrey D. Ullman</author>
</authors>
<publisher>Addison Wesley</publisher>
<published>1986-01-01</published>
<price>102.00</price>
<purchaseDate>2005-01-22</purchaseDate>
</book>
<borrowers>
<borrower id="1">
<name> John Doe </name>
<phone> 555-1212 </phone>
<borrowed>
<book asin="0138613370"/>
<book asin="0122513363"/>
</borrowed>
</borrower>
</borrowers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
XQuery 也有一个“for”循环/子句。
这里有几个例子。
第一个示例是,如果
和
位于不同的文件中:books.xml
(请注意,第二本书具有与borrowers.xml 文件中的
asin
匹配的asin
。)borrowers.xml
XQuery
结果
这是另一个将
和
数据合并在一个文件中的示例:(注意:结果与上面相同.)
combined.xml
XQuery
XQuery also has a "for" loop/clause.
Here are a couple of examples.
The first example is if the
<book>
and<borrowers>
are in different files:books.xml
(Notice that the second book has an
asin
that matches anasin
in the borrowers.xml file.)borrowers.xml
XQuery
Results
Here's another example with the
<book>
and<borrower>
data combined in a single file:(Note: The results are the same as above.)
combined.xml
XQuery
假设
和
元素是
元素的子元素(以使 XML 格式良好) ,这只是Assuming the
<book>
and<borrower>
elements are children of a<library>
element (to make the XML well formed), it's just