1

I'm trying to perform a simple query to get all Uris which has element localName. However, all documents are namespace qualified and I'm not aware of how many namespaces exist? Is there a way I can provide a wildcard in prefix or any other way to get all docs with localName regardless of their namespace ?

cts:element-value-match(xs:QName("*:localName"), "*", ("collation=http://marklogic.com/collation/codepoint"))

This doesn't work for me.

bosari
  • 1,922
  • 1
  • 19
  • 38

1 Answers1

1

No, it is not possible to construct a QName with a wildcard.

Unfortunately, there isn't an element QName lexicon available either.

You could try doing some sampling, or a recursive search that looks for documents that have elements with that local-name, excluding the QNames of elements that you already know about. Something like this:

xquery version "1.0-ml";

declare function local:reportNamespacesFor($localName, $known-namespaces) {
  let $namespace :=
    if ($known-namespaces)
    then cts:search(doc(), cts:not-query( $known-namespaces ! cts:element-query(fn:QName(., $localName), cts:true-query())) )[1]//*[local-name() eq $localName and not(namespace-uri() = $known-namespaces)]/namespace-uri()
    else doc()[//*[local-name() eq $localName]][1]//*[local-name() eq $localName]/namespace-uri()
  return
    if ($namespace)
    then local:reportNamespacesFor($localName, ($known-namespaces, $namespace))
    else distinct-values($known-namespaces)
};

let $localName := "localName"
let $namespaces := local:reportNamespacesFor($localName, ())
let $qnames := $namespaces ! fn:QName(., $localName)
let $count := xdmp:estimate(cts:search(doc(), cts:element-query($qnames, cts:true-query())))
return "There are "||$count||" documents that have the element "||$localName||" bound to the namespaces "||$namespaces  
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147