Xquery 如何使用marklogic获取xml中的项目计数

Xquery 如何使用marklogic获取xml中的项目计数,xquery,marklogic,Xquery,Marklogic,我是MarkLogic新手。我需要从下面的XML中获取图书总数。有人能推荐我吗 <bk:bookstore xmlns:bk="http://www.bookstore.org"> <bk:book category='Computer'> <bk:author>Gambardella, Matthew</bk:author> <bk:title>XML Developer's Guide</bk:title>

我是MarkLogic新手。我需要从下面的XML中获取图书总数。有人能推荐我吗

<bk:bookstore xmlns:bk="http://www.bookstore.org">
<bk:book category='Computer'>
    <bk:author>Gambardella, Matthew</bk:author>
    <bk:title>XML Developer's Guide</bk:title>
    <bk:price>44.95</bk:price>
    <bk:publish_year>1995</bk:publish_year>
    <bk:description>An in-depth look at creating applications with XML. 
</bk:description>
</bk:book>
<bk:book category='Fantasy'>
    <bk:author>Ralls, Kim</bk:author>
    <bk:title>Midnight Rain</bk:title>
    <bk:price>5.95</bk:price>
    <bk:publish_year>2000</bk:publish_year>
    <bk:description>A former architect battles corporate zombies, an evil 
 sorceress, and her     own childhood to become queen of the world. 
</bk:description>
</bk:book>
<bk:book category='Comic'>
    <bk:author>Robert M. Overstreet</bk:author>
    <bk:title>The Overstreet Indian Arrowheads Identification </bk:title>
    <bk:price>2000</bk:price>
    <bk:publish_year>1991</bk:publish_year>
    <bk:description>A leading expert and dedicated collector, Robert M. 
    Overstreet has been writing The Official Overstreet Identification and 
 Price 
  Guide to Indian Arrowheads for more than 21 years</bk:description>
  </bk:book>
 <bk:book category='Comic'>
    <bk:author>Randall Fuller</bk:author>
    <bk:title>The Book That Changed America</bk:title>
    <bk:price>1000</bk:price>
    <bk:publish_year>2017</bk:publish_year>
    <bk:description>The New York Times Book Review Throughout its history 
   America has been torn in two by debates over ideals and beliefs. 
  </bk:description>
  </bk:book>
  </bk:bookstore>

马修·甘巴德拉
XML开发人员指南
44.95
1995
深入了解如何使用XML创建应用程序。
拉尔斯,金
夜雨
5.95
2000
一位前建筑师与邪恶的企业僵尸战斗
女巫,和她自己的童年成为世界女王。
罗伯特·M·奥弗斯特里特
印度箭头识别
2000
1991
领先的专家和专注的收藏家,罗伯特M。
Overstreet一直在写官方的Overstreet身份证明和
价格
超过21年的印度箭头指南
兰德尔·富勒
改变美国的书
1000
2017
《纽约时报》历史书评
美国被理想和信念的争论撕成两半。

任何人都能找到这个问题的解决方案,因为我是新手。

我建议使用
cts:count aggregate
结合
cts:element reference
。这要求您有一本关于
的书

cts:count-aggregate(cts:element-reference(fn:QName("http://www.bookstore.org", "book")))
如果性能不太关键,并且文档计数也不太大,您也可以使用
fn:count
进行计数

declare namespace bk="http://www.bookstore.org";
fn:count(//bk:book)
试试这个-

declare namespace bk="http://www.bookstore.org";

let $book_xml := 
<bk:bookstore xmlns:bk="http://www.bookstore.org">
  </bk:book>
   ........
   ........
  </bk:book>
</bk:bookstore>

return fn:count($book_xml//bk:book)
declare namespace bk=”http://www.bookstore.org";
让$book_xml:=
........
........
返回fn:count($book\u xml//bk:book)

希望有帮助

到目前为止你试过什么?它是否需要扩展到数百万本书?