View check-for-locked-resources.xq
xquery version "3.1";
(: You might've forgotten to close a document opened via WebDAV :)
let $col := "/db/apps/frus-dates"
for $resource in xmldb:get-child-resources($col)
let $user := xmldb:document-has-lock($col, $resource)
$resource || ": " || (if ($user) then $user else "(not locked)")
View index-backed-distinct-values.xq
xquery version "3.1";
(: In eXist-db, distinct-values() is not backed by range indexes.
To achieve better performance for this operation, use util:index-keys.
This sample retrieves all distinct indexed values for the @ref attribute. :)
util:index-keys(collection("/db/apps/my-app/data")//@ref, (),
    function($key, $count) {
    }, -1, "range-index")
View save-db-resource-zip-to-disk.xq
xquery version "3.1";
(: Save a resource stored in eXist to the file system as a zip file :)
let $source := "/db/apps/frus-dates/data/frus-dates.xml"
let $destination := "/Users/joe/Downloads/"
let $preserve-collection-structure := false()
compression:zip(xs:anyURI($source), $preserve-collection-structure),
View equal-and-not.xq
xquery version "3.1";
(1, 2) = (2, 3),
(1, 2) != (2, 3),
not((1, 2) = (2, 3))
View semver.xq
xquery version "3.1";
(:~ Analyze and compare Semantic Versioning (semver) 2.0.0 strings, using XQuery.
@author Joe Wicentowski
declare namespace semver = "";
(:~ Analyze a semver string

Notes in preparation for a blog post or article.


  • Whitespace in the original document
    • As entered, or introduced/manipulated by an editor's functions, such as oXygen's "Format and indent" (and settings thereof), or features, such as Atom's default behavior of trimming trailing whitespace
  • How the document is exposed to the XQuery processor
    • Fetched (get) via a query from the network (doc(), hc:send-request()) or file system (file:read(), xmldb:store-files-from-pattern())
    • Uploaded (put) to the database and stored via REST, WebDAV, XML-RPC
    • Included inline in a query, as an in-memory node; whitespace in in-memory nodes is affected by boundary-space strip|preserve (default is strip)
View parse-date-range-phrases.xq
xquery version "3.1";
declare namespace tei="";
import module namespace dates="" at "/db/apps/tumblr/modules/date-parser.xqm";
import module namespace iu = "" at "/db/import-utilities.xqm";
for $section in doc('/db/apps/administrative-history/timeline.xml')//tei:div
let $head := $section/tei:head
let $date-string := $head/string()
View enrich-month-year-phrases.xq
declare namespace tei="";
import module namespace functx="" at "/db/system/repo/functx-1.0/functx/functx.xql";
(: drew on technique from :)
let $months := (
"jan", "january", "enero", "janvier", "januar", "gennaio",
"feb", "february", "febrero", "fevrier", "februar", "febbraio",
"mar", "march", "marzo", "mars", "marz", "marzo",
View oxygen-saxon-xquery-update-sample.xq
xquery version "3.0";
(: This query shows how to use the XQuery Update Facility (supported by oXygen's built-in
XQuery processor, Saxon-EE XQuery 9.x).
Run this in oXygen's XQuery Debugger mode, using Window > Open Perspective > XQuery Debugger.
Then select this file from the "XQuery:" toolbar dropdown menu, and click the blue triangle
icon in the toolbar to execute the script. Assuming all goes as planned, you will see a small
window appear, with a yellow triangle icon, saying something like, "The document was modified."
View environment-variables.xq
xquery version "3.1";
element environment-variables {
for $var in available-environment-variables()
order by $var
element environment-variable {
attribute name { $var },
attribute value { environment-variable($var) }