
op:from-docs( $cts-query as cts:query, $context-path as xs:string, $column-specs as map:map, [$qualifier as xs:string?], [$system-cols as map:map?], $namespaces as map:map()? ) as map:map
This function dynamically maps semi-structured data (JSON/XML) into rows and columns without deploying a TDE template. It enables ad-hoc queries similar to Virtual Template Views but with additional flexibility, such as node output and advanced column customization.
| Parameters | |
|---|---|
| $cts-query | Query to select documents for row generation . The query can be a cts:query or a string as a shortcut for a cts:word-query. |
| $context-path | XPath applied to each matched document; each result becomes a row. |
| $column-specs | The column definitionss create by using op:column-builder |
| $qualifier | Specifies a name for qualifying the column names in place of the combination of the schema and view names. Use cases for the qualifier include self joins. Using an empty string removes all qualification from the column names. |
| $system-cols | An optional named fragment id column returned by op:fragment-id-col. One use case for fragment ids is in joins with lexicons or document content. |
| $namespaces | Namespaces prefix (key) and uri (value). |
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()
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.