Skip to content

XPath functions ​

The XPath functions available, by group, with those that accept a collation and those that are unavailable or limited. The groups matter only with the lean entry point, where each group is added separately.

@exemplarjs/xpath includes every function on this page. @exemplarjs/xpath/lean includes only the core functions; the other groups are added explicitly. The math:, map: and array: prefixes are predeclared.

The groups ​

GroupImportExportHas
Corealways thereString, numeric, sequence, node and context functions
date-time@exemplarjs/xpath/groups/date-timedateTimeFunctionsDate and time components, timezone adjustment, the current date and time
formatting@exemplarjs/xpath/groups/formattingformattingFunctionsFormatting numbers and dates
regex@exemplarjs/xpath/groups/regexregexFunctionsRegular expressions
higher-order@exemplarjs/xpath/groups/higher-orderhigherOrderFunctionsFunctions that take function items
maps@exemplarjs/xpath/groups/mapsmapFunctionsThe map: functions
arrays@exemplarjs/xpath/groups/arraysarrayFunctionsThe array: functions
json@exemplarjs/xpath/groups/jsonjsonFunctionsParsing JSON and converting it to and from XML
resources@exemplarjs/xpath/groups/resourcesresourceFunctionsReading documents, text and collections
serialization@exemplarjs/xpath/groups/serializationserializationFunctionsserialize

Map and array constructors, lookups with ?, inline functions and the arrow operator are part of the language and need no group.

Core ​

KindFunctions
Stringsstring string-length normalize-space concat string-join substring substring-before substring-after contains starts-with ends-with contains-token upper-case lower-case translate compare codepoint-equal codepoints-to-string string-to-codepoints normalize-unicode collation-key
URIsencode-for-uri iri-to-uri escape-html-uri resolve-uri
Numbersnumber abs ceiling floor round round-half-to-even
Mathematicsmath:pi math:exp math:exp10 math:log math:log10 math:sqrt math:pow math:sin math:cos math:tan math:asin math:acos math:atan math:atan2
Booleanstrue false boolean not
Sequencesempty exists count head tail reverse unordered insert-before remove subsequence distinct-values index-of deep-equal zero-or-one one-or-more exactly-one
Aggregatessum avg max min
Nodesname local-name namespace-uri node-name root path has-children data nilled base-uri document-uri lang generate-id innermost outermost
IDsid element-with-id idref
Contextposition last static-base-uri default-collation default-language environment-variable available-environment-variables
Qualified namesQName resolve-QName prefix-from-QName local-name-from-QName namespace-uri-from-QName namespace-uri-for-prefix in-scope-prefixes
Errors and tracingerror trace
XQuery and XSLTload-xquery-module transform (both always raise an error)

Constructor functions such as xs:integer('5') and xs:date('2024-01-01') are core too, for every built-in atomic type. See Getting results and Regular expressions and collations.

date-time ​

KindFunctions
Components of a dateTimeyear-from-dateTime month-from-dateTime day-from-dateTime hours-from-dateTime minutes-from-dateTime seconds-from-dateTime timezone-from-dateTime
Components of a dateyear-from-date month-from-date day-from-date timezone-from-date
Components of a timehours-from-time minutes-from-time seconds-from-time timezone-from-time
Components of a durationyears-from-duration months-from-duration days-from-duration hours-from-duration minutes-from-duration seconds-from-duration
Timezonesadjust-dateTime-to-timezone adjust-date-to-timezone adjust-time-to-timezone implicit-timezone
Current date and timecurrent-dateTime current-date current-time
Construction and parsingdateTime parse-ietf-date

See Dates, times and durations.

formatting ​

format-integer format-number format-dateTime format-date format-time

See Dates, times and durations.

regex ​

matches replace tokenize analyze-string

See Regular expressions and collations.

higher-order ​

KindFunctions
Over a sequencefor-each filter fold-left fold-right for-each-pair sort
Function itemsfunction-lookup function-name function-arity apply
Random numbersrandom-number-generator

See Maps, arrays, JSON and functions.

maps ​

map:merge map:size map:keys map:contains map:get map:find map:put map:entry map:removemap:for-each

See Maps, arrays, JSON and functions.

arrays ​

KindFunctions
Accessarray:size array:get array:head array:tail array:subarray array:flatten
Modificationarray:put array:append array:remove array:insert-before array:reverse array:join
Higher-orderarray:for-each array:filter array:fold-left array:fold-right array:for-each-pair array:sort

See Maps, arrays, JSON and functions.

json ​

parse-json json-to-xml xml-to-json

json-doc reads a resource, so it is in resources. See Maps, arrays, JSON and functions.

resources ​

KindFunctions
XML documentsdoc doc-available parse-xml parse-xml-fragment
Textunparsed-text unparsed-text-lines unparsed-text-available
JSONjson-doc
Collectionscollection uri-collection

These functions read nothing unless the evaluation is given a resolver. See Reading documents and collections.

serialization ​

serialize

See Serializing results.

Functions that take a collation ​

A collation is a named set of rules for comparing and ordering strings, identified by a URI. Each of these functions takes a collation URI as an optional last argument, and uses the default collation without one. sort and array:sort take it as their second argument.

KindFunctions
Comparingcompare deep-equal
Substring matchingcontains starts-with ends-with substring-before substring-after contains-token
Value matchingdistinct-values index-of
Orderingmax min sort array:sort
Keyscollation-key

Operators such as = and lt always use the default collation, which is the codepoint collation unless the compiler's defaultCollation option names another. See Regular expressions and collations.

Not available or limited ​

Function or featureWhat happens instead
environment-variable, available-environment-variablesReport no variables, so an expression cannot read the process environment
load-xquery-moduleRaises FOQM0006: there is no XQuery processor
transformRaises FOXT0004: there is no XSLT processor
json-to-xml with the validate optionRaises FOJS0004: validation requires schema support
parse-json and json-to-xml with the liberal optionThe option is accepted, but only strict JSON is parsed
format-number with a named decimal formatRaises FODF1280: only the default decimal format exists
format-date, format-dateTime, format-time: a calendar other than AD or ISOWrites the Gregorian date after a [Calendar: AD] marker
format-date, format-dateTime, format-time: a placeThe place is ignored; timezones are written as offsets, never as names
format-date, format-dateTime, format-time: a language the runtime lacks, or number words outside EnglishWrites English after a [Language: en] marker
format-integer with words or ordinalsAlways English
collation-key with a Unicode (UCA) collationRaises FOCH0004; the codepoint and HTML case-insensitive collations produce keys
A collation other than codepoint, HTML case-insensitive or Unicode (UCA)Raises FOCH0002
function-lookup in the lean entryFinds a function only when its group has been added
A group inside a repeated group in a regular expressionIs reset on each repetition: replace('ab', '((a)|b)+', '[$2]') returns []
schema-element() and schema-attribute() testsRaise XPST0008: schemas are not supported

Language support ​

Part of XPath 3.1Supported
The whole XPath 3.1 grammarYes; anything else raises XPST0003
All axes, including namespace::Yes
Maps, arrays, ? lookups, inline functions, =>, !, || and letYes
Function items and higher-order functionsYes
Types from a schemaNo: elements are xs:untyped and attributes xs:untypedAtomic
XPath 1.0 compatibility modeNo

Released under the Apache License 2.0.