Loading TOC...


   $value as String
) as Number


Returns an integer representing the number of times in which a particular value occurs in a value lexicon lookup (for example, cts:element-values). When using the fragment-frequency lexicon option, cts:frequency returns the number of fragments in which the lexicon value occurs. When using the item-frequency lexicon option, cts:frequency returns the total number of times in which the lexicon value occurs in each item.

$value A value from a value lexicon lookup. The value should be one returned from the cts:element-values, cts:element-attribute-values, or the corresponding value-match lexicon APIs.

Usage Notes

You must have a Range index configured to use the value lexicon APIs (cts:element-values, cts:element-value-match, cts:element-attribute-values, or cts:element-attribute-value-match).

If the value specified is not from a value lexicon lookup, cts:frequency returns a frequency of 0.

The frequency returned from cts:frequency is fragment-based by default (using the default fragment-frequency option in the lexicon API). If there are multiple occurences of the value in any given fragment, the frequency is still one per fragment when using fragment-frequency. Therefore, if the value returned is 13, it means that the value occurs in 13 fragments.

If you want the total frequency instead of the fragment-based frequency (that is, the total number of occurences of the value in the items specified in the cts:query option of the lexicon API), you must specify the item-frequency option to the lexicon API value input to cts:frequency. For example, the second example below specifies an item-frequency and a cts:document-query in the lexicon API, so the item frequency is how many times each speaker speaks in the play (because the constraining query is a document query of hamlet.xml, which contains the whole play).


const arr = new Array();
const x = cts.elementValues(xs.QName("SPEAKER"),"", null,
for (const speaker of x) {
  arr.push([speaker, cts.frequency(speaker)]);
const obj = new Object();
obj.speakerSpeaks = arr;

=> Returns the names of the speakers in Hamlet
   with the number of times they speak. If the
   play is fragmented at the SCENE level, then
   it returns the number of scenes in which each
   speaker speaks. 

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


The commenting feature on this page is enabled by a third party. Comments posted to this page are publicly visible.