marklogic Working with fn:count, xdmp:estimate and cts:frequency Using fn:count() to get the number of matching documents


The XML document, I will be using throughout the examples is -


The following queries returns the number of documents with value fragment-d for element d -

  • Using a cts:search

    fn:count(cts:search(fn:doc(), cts:element-value-query(xs:QName("d"), "fragment-d")))

  • Using XPath