[英]How do I get count of records using XQuery
我有包含書籍記錄的“Library.xml”文件
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>DBMS</title>
<author>Korth</author>
<publisher>Pragati</publisher>
<price>500</price>
</book>
<book>
<title>C Programming</title>
<author>Balguruswami</author>
<publisher>Vision</publisher>
<price>1250</price>
</book>
<book>
<title>DBMS</title>
<author>Balguruswami</author>
<publisher>Vision</publisher>
<price>1300</price>
</book>
<book>
<title>DBMS</title>
<author>Ramakrishna</author>
<publisher>Nirali</publisher>
<price>350</price>
</book>
<book>
<title>C++</title>
<author>E Balguruswami</author>
<publisher>Techmax</publisher>
<price>350</price>
</book>
</library>
如何僅使用XQuery - FLOWER獲得 DBMS 書籍的數量? 我試過這個:
let $books := (doc("LibraryXML.xml")/library/book)
return <result>
{
for $x in $books
where $x/title = "DBMS"
return count($x)
}
</result>
根據library.xml答案應該是 3。但我得到的是:
<?xml version="1.0" encoding="UTF-8"?>
<result>1 1 1</result>
要在 XQuery 3.0 中做到這一點,不需要包含所有子句的完整 FLWOR 表達式。
一探究竟。
XQuery
let $library := doc("e:\Temp\LibraryXML.xml")/library/book[title='DBMS']
return <result>{count($library)}</result>
Output
<result>3</result>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.