add Attribute Index
Type: Function
How to get addAttributeIndex?
JavaScript
import addAttributeIndex from 'fontoxml-indices/src/addAttributeIndex.js'
Note: This feature is experimental and subject to change.
Adds an attribute index and registers a XPath function to access it. The XPath function will be registered with the provided functionNamespaceURI
and functionLocalName
.
This will index all elements which have the attribute providing a quick lookup.
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 attribute index in the install.js
it will be loaded later making it unavailable in XQuery modules.
Example
This example registers the function app:id(xs:anyAtomicType)
as element()*
: a function that accepts any atomic type (xs:string, xs:numeric, etc) and returns zero or more elements. In this example, the editor instance registers the app
prefix to the application-specific namespace URI of http://www.fontoxml.com/app/your-app-name-here
. By executing this function we get the element(s) with the provided id ("123").
JavaScript
import addAttributeIndex from 'fontoxml-indices/src/addAttributeIndex.js';
addAttributeIndex(
'http://www.w3.org/XML/1998/namespace',
'id',
'http://www.fontoxml.com/app/your-app-name-here',
'id'
);
const node = evaluateXPathToFirstNode(`app:id("123")`);
...
Arguments
attribute
Namespace UR I (Required)
Type: String | NULL
The namespace URI of the attribute.
attribute
Local Name (Required)
Type: String
The local name of the attribute.
function
Namespace UR I (Required)
Type: String
The namespace URI of the function.
function
Local Name (Required)
Type: String
The local name of the function.