
op:xpath( $column as item(), $path as xs:string, [$namespaceBindings as map:map?] ) as map:map
This function extracts a sequence of child nodes from a column with node values -- especially, the document nodes from a document join. The path is an XPath (specified as a string) to apply to each node to generate a sequence of nodes as an expression value.
| Parameters | |
|---|---|
| $column | The name of the column from which to extract the child nodes. The column can be named with a string or a column function such as op:col, op:view-col, or op:schema-col, or constructed from an expression with the op:as function.It can also be op:context to refer to the node of the current processing row. |
| $path | An XPath (specified as a string) to apply to each node. |
| namespaceBindings | A map of namespace bindings. The keys should be namespace prefixes and the values should be namespace URIs. These namespace bindings will be added to the in-scope namespace bindings in the evaluation of the path. |
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
op:from-literals((
map:entry("id", 1) => map:with("val", 2) => map:with("uri", "/employee1.json"),
map:entry("id", 2) => map:with("val", 4) => map:with("uri", "/employee3.json"),
map:entry("id", 3) => map:with("val", 6) => map:with("uri", "/expense4.json")
))
=> op:order-by("id")
=> op:join-doc(op:col("doc"), op:col("uri"))
=> op:select(("id", "val", "uri",
op:as("EmployeeID", op:xpath("doc", "/(Employee/ID|Expenses/EmployeeID)"))
))
=> op:result()
op:xpath( $column-builder-plan as map:map, $path as xs:string ) as map:map
Sets the XPath expression in the document from which to extract content for the column created by op:add-column. It cannot be used together with op:expr, as both of them define the content of the column.
xquery version "1.0-ml";
import module namespace op="http://marklogic.com/optic"
at "/MarkLogic/optic.xqy";
op:from-docs(
cts:collection-query("fromDocsColl"),
"/my:root",
op:column-builder()
=>op:add-column("id")=>op:nullable(fn:true())=>op:type("integer")=>op:default(-1)
=>op:add-column("name")=>op:expr(op:xpath(op:context(),"my2:name"))=>op:collation("http://marklogic.com/collation/codepoint")
=>op:add-column("testXpath")=>op:xpath("./my2:name" )
=>op:add-column("node")=>op:type("node")=>op:xpath(".")
=>op:add-column("vector")=>op:xpath("./my2:vector")=>op:type("vector")=>op:dimension(3)
=>op:add-column("geo")=>op:type("point")=>op:xpath("./my2:geo" )=>op:coordinate-system("wgs84/double")=>op:units("miles"),
"TEST",
op:fragment-id-col("myFragmentIdCol"),
map:entry("my","https://www.example.com/my")=>map:with("my2","https://www.example.com/my2")
)
=>op:select(("id","name","testXpath","node","vector","geo","myFragmentIdCol"))
=>op:result()