Skip to content

Instantly share code, notes, and snippets.

joewiz / show-http-request-headers.xq
Created Oct 22, 2019
Display all HTTP request headers for the current request (eXist-db)
View show-http-request-headers.xq
xquery version "3.1";
array {
request:get-header-names() ! map { . : request:get-header(.) }
joewiz / youngest-principal-officers-by-position.xq
Created Oct 21, 2019
Sort Principal Officers in a position by age at time of appointment
View youngest-principal-officers-by-position.xq
xquery version "3.1";
(: For a given Principal Officer position, calculate the age of the official at the time of
: appointment; sort the results by age. For officials missing birth or appointment dates,
: return the age as 0 to identify these as outliers with incomplete information.
array {
let $principal-id := "assistant-secretary-legislative-affairs"
let $principal-doc := doc("/db/apps/pocom/positions-principals/" || $principal-id || ".xml")
joewiz / create-travels-tsv.xq
Last active Mar 14, 2019
Generate a TSV of Travels of the Secretary of State
View create-travels-tsv.xq
xquery version "3.1";
(: Generate a TSV of Travels of President and Secretary of State.
: Assumes has been installed.
: A function for constructing a TSV (tab-separated value) file
: @param A sequence of column headings
joewiz / xquery-3.1-boilerplate.xq
Created Mar 4, 2019
XQuery 3.1 module boilerplate
View xquery-3.1-boilerplate.xq
xquery version "3.1";
(: Standard namespaces from :)
declare namespace array="";
declare namespace err="";
declare namespace fn="";
declare namespace map="";
declare namespace math="";
declare namespace output="";
declare namespace xs="";
joewiz /
Created Feb 5, 2019
Thoughts on a "package library" to replace eXist's "public repo"



  1. add package
    • receive uploaded xar(s)
    • store upload(s) in "temp" folder
    • for each new package:
      • extract package metadata
      • validate package metadata
joewiz / data-composition.xqy
Last active Jun 4, 2019 — forked from xquery/data-composition.xqy
This works in BaseX and Saxon, but eXist returns an error: `exerr:ERROR cannot convert function(*)('') to a node set [at line 59, column 15]`
View data-composition.xqy
xquery version "3.0";
(: discovered via, updated with HTTP URL for data.xq :)
(: the power of algebraic data types in xquery
This example shows how we can composite up data models
which 'carry' their own operations along with them.
joewiz / CompareTools.plist
Last active Feb 14, 2019
Add oXygen as Diff & Merge Tool for Git Tower
View CompareTools.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
<plist version="1.0">
<string>Diff Directories</string>
joewiz / 01-levenshtein-distance.xq
Last active Jun 4, 2019
Calculate Levenshtein Distance, using XQuery
View 01-levenshtein-distance.xq
xquery version "3.1";
Calculate Levenshtein Distance, using XQuery
@author Guillaume Mella
declare function local:levenshtein-distance($string1 as xs:string?, $string2 as xs:string?)
as xs:integer
joewiz / adaptive-serialization.xq
Created Sep 15, 2018
Boilerplate for declaring Adaptive serialization in XQuery
View adaptive-serialization.xq
xquery version "3.1";
declare namespace output="";
declare option output:method "adaptive";
declare option output:indent "yes";
map { "reference": xs:anyURI("") }
joewiz / date-parser.xqm
Created Aug 26, 2018
Parse various formats of date strings, in XQuery
View date-parser.xqm
xquery version "3.1";
Various Date String Parser
- Parses various flavors of date strings, returns as xs:dateTime or xs:date
- Key functions: dates:parseDateTime() and dates:parseDate()
- Adapted by Joe Wicentowski from
- Adapted to standard XQuery (instead of the MarkLogic 0.9-ml flavor)
- TODO: test against