evaluateXPath

How to get evaluateXPath

ES2015+:

import evaluateXPath from 'fontoxml-selectors/evaluateXPath'

ES5:

define([
	'fontoxml-selectors/evaluateXPath'
], function (
	evaluateXPath
) {
});

Type: Function

Evaluate any XPath query or XQuery script. Set the options.language property to evaluateXPath.XQUERY_3_1_LANGUAGE to run XQuery. Refer to registerXQueryModule for more information on XQuery modules.

Arguments

# Name Type Description
1. xpathString XPathQuery

The XPath to evaluate

2. contextNode Node | Null

The initial context of the query. If context is absent, it is still possible to evaluate some queries, like '1+1', or queries using only variables.

3. domFacade Blueprint

The blueprint (or blueprint compatible interface) to use for this query.

4. variables Object<String | any>

Any variables to use for this query. They will be prefixed with a '$' sign


  Default value
{}
5. expectedResultType Number

The expected result type for the query. Use one of the static properties present on this function.


  Default value
0
6. options Object<String | any>

See https://github.com/FontoXML/fontoxpath for more info on this parameter.


  Default value
{}

Static properties

Name Type Description
evaluateXPath.ANY_TYPE Number

Returns the result of the query, can be anything depending on the query

evaluateXPath.ARRAY_TYPE Number

Resolve to a JSON array using an algorithm inspired by JSON.

The following transformations are used:

  • XPath arrays (the item created using the array{...} or [...] syntaxes) are transformed to JavaScript arrays,

  • Maps to JavaScript objects, the keys are converted to strings. If this means a duplicate key occurs, an error is thrown,

  • Nodes are outputted as nodes,

  • Numbers, booleans and strings are outputted as their JavaScript counterparts,

  • Zero length sequences are the null value,

  • Sequences with a length greater than 1 cause an error.

evaluateXPath.BOOLEAN_TYPE Number

Resolves to true or false, uses the effective boolean value to determine the result. count(1) resolves to true, count(()) resolves to false

evaluateXPath.FIRST_NODE_TYPE Number

Resolves to the first node evaluateXPath.NODES_TYPE would have resolved to.

evaluateXPath.MAP_TYPE Number

Resolve to a JSON object using an algorithm inspired by JSON.

The following transformations are used:

Maps to JavaScript objects, the keys are converted to strings. If this means a duplicate key occurs, an error is thrown

XPath arrays are transformed to JavaScript arrays,

Nodes are outputted as nodes,

Numbers, booleans and strings are outputted as their JavaScript counterparts,

Zero length sequences are the null value,

Sequences with a length greater than 1 cause an error

evaluateXPath.NODES_TYPE Number

Resolve to all nodes the XPath resolves to. Returns nodes in the order the XPath would. Meaning (//a, //b) resolves to all A nodes, followed by all B nodes. //*[self::a or self::b] resolves to A and B nodes in document order.

evaluateXPath.NUMBER_TYPE Number

Resolve to a number, like count((1,2,3)) resolves to 3.

evaluateXPath.NUMBERS_TYPE Number

Resolve to an array of numbers

evaluateXPath.STRING_TYPE Number

Resolve to a string, like //someElement[1] resolves to the text content of the first someElement

evaluateXPath.STRINGS_TYPE Number

Resolve to an array of strings

evaluateXPath.XQUERY_3_1_LANGUAGE String

Set options.language to evaluateXPath.XQUERY_3_1_LANGUAGE to execute the given expression as an XQuery script. Please refer to the documentation of github.org/FontoXML/fontoxpath for more information on which language constructs are integrated.

Returns

Type: any

The result of the query. The type depends on the value of the 'expectedResultType' parameter.