Loading TOC...


   $arg as xs:double*
) as xs:double?


Returns a frequency-weighted median of a sequence. This function works like math:median except each item in the sequence is repeated cts:frequency times before calculating the median. If $arg is the empty sequence, the function returns the empty sequence.

arg The sequence of values. The values should be the result of a lexicon lookup.

Usage Notes

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 be the empty sequence.


xquery version "1.0-ml";

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

cts:median(cts:element-values(xs:QName("int"), (),
           ("type=int", "item-frequency"))),
cts:median(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.