Type: Function

How to get addReducer?


import addReducer from 'fontoxml-indices/src/addReducer.js'

Registers an XPath function which can be used to accumulate values.

We recommend this to be done in the configureSxModule.js of a package, this allows XQuery modules to use an attribute index. If you instead add the reducer in the install.js it will be loaded later making it unavailable in XQuery modules.

The accumulated value of the current node matching the selector can be retrieved using the XPath function which is registered with the provided reducerFunctionNamespaceURI and reducerFunctionLocalName.

The provided callbackFunctionNamespaceURI and callbackFunctionLocalName will be used to calculate the accumulated value of a node. This function needs to be registered and allows you to determine how a value should be calculated based on the previous and its relation to it. The function must match the following signature:


declare function app:myReducerForSectionNumbering(
	$previousAccumulator as item()*,
	$relType as xs:string,
	$node as node(),
	$isUnloaded as xs:boolean
) as item()* {
	(: Compute a new accumulator value for $node :)

It has the following arguments:

  • $previousAccumulator as item()* The accumulated value of the previous node. Meaning the type of item()* will be of the same type as we return as it is the value this function returned for the previous node.

  • $relType as xs:string Indicates the relation between the previous and the current matched $node. To determine the relation we take both the DOM and documents hierarchy into account. This will be one of the following values: "first", "parent", or "sibling".

    • "first" The $node is the first one which matches.

    • "parent" The $node is a descendant of the previous node.

    • "sibling" The $node is a sibling of the previous node.

  • $node as node() The current node which matched the selector.

  • $isUnloaded as xs:boolean This argument is true when the selector does not match the source node and the document we need to check is unloaded. In this case $node will be the source node referencing the unloaded document. You can potentially use the source node to generate the correct numbering.

See Create a numbering for nodes for examples.


  1. reducerFunctionNamespaceURI


    Type: String | NULL

    The namespace URI of the reducer function.

  2. reducerFunctionLocalName


    Type: String

    The local name of the reducer function.

  3. selector


    Type: String

    The selector indicating which elements to accumulate.

  4. callbackFunctionNamespaceURI


    Type: String | NULL

    The namespace URI of the callback function.

  5. callbackFunctionLocalName


    Type: String

    The local name of the callback function.