xpathexist-dbxquery-3.0

XPATH 2.0 collection() with "?select=" (in eXist-db / XQuery)


Using XPath 2.0 in eXist 4.4 and XQuery.

I have a series of documents in eXist-db directory /db/apps/deheresi/data which I want to retrieve with collection(), but using a wildcard or predicate to filter specifically-named documents.

For example, I'd like to get the documents that begin with ABC and end with .xml. I thought a wildcard like so ?select=ABC*.xml would work, but it's not returning the expected results.

collection("/db/apps/deheresi/data?select=ABC*.xml")

I also tried to apply a combination of starts-with and ends-with but to no success. I am no doubt overlooking something simple here.

Thanks in advance.


Solution

  • One way of doing this in exist

    xquery version "3.1";
    (: get document names :)
     let $doc-names := for $n in collection('/db/apps/deheresi/data')
     return
        util:document-name($n)
    
    (: apply filter :)
     for $f in $doc-names[matches(., '^ABC.*\.xml$')]
     return
      $f