cts:search pass the node dynamically

Viewed 28

Is there a way to have the below code working?

let $node := 'childnode'
return
cts:search(/root/$node, 
    cts:and-query((
        cts:collection-query('collection')
        
    ))
  )
1 Answers

One way to dynamically build and execute the XPath for the cts:search $expression parameter is to generate the search expression as a string and then use xdmp:value() to parse and execute:

let $node := 'childnode'  
let $expression:= "/doc/" || $node
let $query as cts:query := cts:and-query((
        cts:collection-query('collection')
    ))
return xdmp:value("cts:search("||$expression||"," ||$query||")")
Related