Loading TOC...


   $arg as xs:anyAtomicType*,
   [$zero as xs:anyAtomicType?]
) as xs:anyAtomicType?


[DEPRECATED: use cts:sum-aggregate]

Returns a frequency-weighted sum of a sequence. This function works like fn:sum except each item in the sequence is multiplied by cts:frequency before summing.

arg The sequence of values to be summed. The values should be the result of a lexicon lookup.
zero The value to return as zero if the input sequence is the empty sequence.

Usage Notes

The cts:frequency of the result is the sum of the frequencies of the sequence.

This function is designed to take a sequence of values returned by a lexicon function (for example, cts:element-values); if you input non-lexicon values, the result will always be 0.


xquery version "1.0-ml";

   This query assumes an int range index
   is configured in the database. It
   generates some sample data and then
   performs the aggregation in a separate
for $x in 1 to 10
xdmp:document-insert(fn:concat($x, ".xml"),
  for $y in 1 to $x
  return <int>{$x}</int>

cts:sum(cts:element-values(xs:QName("int"), (),
           ("type=int", "item-frequency"))),
cts:sum(cts:element-values(xs:QName("int"), (),
           ("type=int", "fragment-frequency")))

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.