Reputation: 976
After using the below mentioned Xquery I am getting the output correctly.
let $element :="Name"
let $value := "Antony"
let $op := cts:search(//root, cts:element-value-query( xs:QName($element),$value))
return $op
But I am getting error while using "root" value in variable. Please suggest me, if any other options?
let $element := "Name"
let $value := "Antony"
let $root := "root"
let $op := cts:search(//$root, cts:element-value-query( xs:QName($element),$value))
return $op
Error :
[1.0-ml] XDMP-UNSEARCHABLE: cts:search(fn:collection()/descendant-or-self::node()/"root", cts:element-value-query(fn:QName("","Name"), "Antony", ("lang=en"), 1)) -- Expression is unsearchable
Stack Trace
At line 16 column 23:
In xdmp:eval("(: let $uri := cts:element-value-query( xs:QName("file...", (), <options xmlns="xdmp:eval"><database>8922589838473153050</database><root>/marklogic/poc/</r...</options>)
$element := "Name"
$value := "Antony"
$root := "root"
14. let $value := "Antony"
15. let $root :="root"
16. **let $op := cts:search(//$root, cts:element-value-query( xs:QName($element),$value))**
17. return $op
Example data:
<root processtype="sample">
<title series="hk">
<Name>Antony</Name>
</title>
</root>
Upvotes: 1
Views: 197
Reputation: 944
you cannot use the $root
value in that way.. in order to match the $root
value you have to do the following //root[. = $root]
let $element :="Name"
let $value := "Antony"
let $root :="root"
let $op := cts:search(//root[. = $root], cts:element-value-query( xs:QName($element),$value))
return $op
Upvotes: 1