Skip to content

xpath3

Written as xpath3(argnum flags):options in a transform expression.

Minimum arguments 1
Maximum arguments 1
Default arguments 1
Argument modes SINGLE_PRIMITIVE

Extract data from XML/HTML content using XPath3 expressions.

Features:

  • Supports standard XPath 3.0/3.1 syntax
  • Works with both XML and HTML content
  • Automatic recovery (with ‘RECOVER XML’ flag) of broken XML. However, use this flag with caution, as this process may not fully recover the original XML document structure when ambiguilty exists.
  • Namespace support:
    • Enabled by default. Can be disabled with ‘IGNORE NAMESPACE’ flag. When ‘IGNORE NAMESPACE’ flag is turned on, namespace mapping is ignored, and the transform’s options data is interpretted as the xpath expression
    • [Optional] Namespace mapping via a preliminary mapping dict before the actual xpath expression, such as {"ns1":"http://mymodel.org/model1/1.0"}||//main//model1

The XPath3 expression (from the transform’s options data) supports 2 forms: - {namespace_mapping}||{xpath_expr}: e.g. {"ns1":"http://mymodel.org/model1/1.0"}||//main//ns1:model1 - {xpath_expr}: e.g. //main//model1

where `{namespace_mapping}` is the namespace mapping dict and `{xpath_expr}` is the actual xpath expression.
Flag Letter
spread_output S
noncaptive_input I
recover_xml r
IGNORE_NAMESPACE N
Input args: ["<html><body><a href=\"link1\">Link 1</a><a href=\"link2\">Link 2</a></body></html>"]
Transforms: "xpath3://a/@href"
Output: ["link1","link2"]
Input args: ["<root><item>First</item><item>Second</item></root>"]
Transforms: "xpath3://item/text()"
Output: ["First","Second"]
Input args: ["<div id=\"main\" class=\"container\"></div>"]
Transforms: "xpath3://div/@class"
Output: ["container"]
Input args: ["<root/>"]
Transforms: "xpath3:math:atan(1.0e0)"
Output: 0.7853981633974483
Input args: ["<root/>"]
Transforms: "xpath3:let $x := 5, $y := 10 return $x + $y"
Output: 15
Input args: ["<root/>"]
Transforms: "xpath3:if (//item) then 'has items' else 'no items'"
Output: ["no items"]
Input args: ["<root/>"]
Transforms: "xpath3:(1 to 5)"
Output: [1,2,3,4,5]
Input args: ["<root/>"]
Transforms: "xpath3:let $f := function($x) { $x * 2 } return $f(5)"
Output: 10
Input args: ["<root/>"]
Transforms: "xpath3:string-join(('a','b','c'), '-')"
Output: "a-b-c"
Input args: ["<root/>"]
Transforms: "xpath3:array { 1, 2, 3 }, map { 'a': 1, 'b': 2 }"
Output: [[1,2,3],{"a":1,"b":2}]
Input args: ["<root/>"]
Transforms: "xpath3:some $x in (1,2,3) satisfies $x > 2"
Output: true
Input args: ["<root/>"]
Transforms: "xpath3:('a','b','c') => count()"
Output: 3
Input args: ["<Parent><Child1/><Child2></Parent>"]
Transforms: "xpath3(r):/Parent/*"
Output: ["<Child1/>","<Child2/>"]
Input args: ["<Parent xmlns=\"http://testxml.org/parent/1.0\"><Child1/><Child2/></Parent>"]
Transforms: "xpath3(r):{\"ns1\":\"http://testxml.org/parent/1.0\"}||/ns1:Parent/*"
Output: ["<Child1 xmlns=\"http://testxml.org/parent/1.0\"/>","<Child2 xmlns=\"http://testxml.org/parent/1.0\"/>"]
Input args: ["<Parent xmlns=\"http://testxml.org/parent/1.0\"><Child1/><Child2/></Parent>"]
Transforms: "xpath3(N):/Parent/*"
Output: ["<Child1 xmlns=\"http://testxml.org/parent/1.0\"/>","<Child2 xmlns=\"http://testxml.org/parent/1.0\"/>"]