Type: Function

How to get addReducer_legacy?


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


This API will be removed in 7.16. Use addReducer instead.

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

Note: we have discovered an issue when reloading the document containing the structure, see Known issues for more information.

We recommend this to be done in the configureSxModule.js of a package, this allows XQuery modules to use the 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(),
	$isSourceNode as xs:boolean
) as item()* {
	(: Compute a new accumulator value for $node :)

It has the following arguments:

  • $previousAccumulator as item()* This will be 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 The relationship type is indicated as "first" only for the first context node the accumulator meets. The relationship type is indicated as "parent" only when the accumulator is executed for a child chunk of the previous iteration, or a descendant node of the previous iteration. In all other cases the relationship type is "sibling".

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

  • $isSourceNode as xs:boolean Whether or not the element is inspected in a loaded document, or instead an element that refers to the unloaded document is inspected. Indicating whether the $node is actually the source node. In case the document is not loaded, we will set this boolean to true and instead pass the source node so we do not have to load the document.

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 items 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.