1
votes

I'm trying to do a search based on an element value. This should return the element value and the document URI having that matching element value. I have written a code as below which is well returning the element value. Not getting document URI. How to get both.

xquery version "1.0-ml";
<results>{
let $x := cts:element-values(fn:QName("http://example.com/dataset","name"), (), ("frequency-order","document"), cts:query(
  <and-query xmlns="http://marklogic.com/cts">
    <word-query>
      <text>paramedical</text>
    </word-query>
    <directory-query>
      <uri>/dataset/</uri>
    </directory-query>
  </and-query>
))
for $dataset in $x
return
(
<result>
  <name>{$dataset}</name>
  <reference>{cts:uris($dataset)}</reference>
</result>
)
}</results>
1

1 Answers

2
votes

Try this:

for $tuple in cts:value-tuples(
  (
    cts:element-reference(fn:QName("http://example.com/dataset","name")),
    cts:uri-reference()
  ),
  ("frequency-order","document"),
  $query
)
return $tuple

You'll need the URI lexicon turned on.