Skip to content

Instantly share code, notes, and snippets.

View joewiz's full-sized avatar

Joe Wicentowski joewiz

  • Arlington, Virginia
View GitHub Profile
@joewiz
joewiz / 00-README.md
Last active January 29, 2022 00:45
Basic dynamic web pages, with XQuery and eXist

Basic dynamic web pages, with XQuery and eXist

This self-guided tutorial builds up from a simple "Hello, World!" exercise to a dynamic web page that responds to user input. It uses eXist-db and teaches the basic interface elements of the eXide XQuery IDE for developing XQuery-based applications in eXist.

eXist is a free, open source native XML database. It's a great tool for learning how to query, analyze, and transform your data. Among the various interfaces for working with eXist, one of the most convenient is eXide, a browser-based IDE (integrated development environment) for writing XQuery modules and developing XQuery-based applications on your own computer without installing any additional software. eXide comes pre-installed with eXist and has a number of useful features. We'll just cover the basics here. And once you have something you'd like to turn into a web page, eXist has a built-in web server, so you can develop full-fledged web applications by learning just a few additional functions and tec

@joewiz
joewiz / ideas-for-exist-db-app-org-repos.md
Last active December 2, 2017 00:16
Ideas for eXist-db org app repos

Ideas for eXist-db org app repos

Incomplete, draft notes toward a proposal for a consideration by the community during a future community call

Goals

  • Have a common set of best practices for maintaining and releasing quality eXist community apps
  • Help maintainers know what they should do
  • Help users know how to report problems, ask questions, and contribute
  • Help the community stay aware of releases
@joewiz
joewiz / an-introduction-to-recursion-in-xquery.md
Last active January 3, 2024 15:30
An introduction to recursion in XQuery

An introduction to recursion in XQuery

  • Created: Nov 28, 2017
  • Updated: Nov 29, 2017: Now covers transformation of XML documents

Recursion is a powerful programming technique, but the idea is simple: instead of performing a single operation, a function calls itself repeatedly to whittle through a larger task. In XQuery, recursion can be used to accomplish complex tasks on data that a plain FLWOR expression (which iterates through a sequence) cannot, such as transforming an entire XML document from one format into another, like TEI or DocBook into HTML, EPUB, LaTeX, or XSL-FO. Transforming a document is well-suited to recursion because each of the document's nodes may need to be examined and manipulated based on the node's type, name, and location in the document; and once a node has been processed, the transformation must continue processing the nodes' children and descendants until the deepest leaf node has been processed. But learning the technique of recursion is often hard for a beginning program

@joewiz
joewiz / enrich-dates-in-mixed-content.xq
Created November 21, 2017 18:38
Enrich dates in mixed content, with XQuery
xquery version "3.1";
(: Turning "December 7, 1941" into <date>December 7, 1941</date> isn't too hard, with XPath 3.0's
fn:analyze-string() function, but if the date string occurs in mixed text, such as:
<p>Pearl Harbor was attacked on <em>December</em> 7, 1941.</p>
and you want to preserve the existing element structure to return:
<p>Pearl Harbor was attacked on <date><em>December</em> 7, 1941</date>.</p>
it's quite a bit more challenging.
This query uses string processing to align the results of fn:string-analyze() with the input's
@joewiz
joewiz / get-latest-created-document.xq
Last active August 14, 2021 08:13
Get the most recently created document in an eXist collection, using XQuery
xquery version "3.1";
(: See discussion at http://markmail.org/message/hpu7toznx3fvdiei :)
import module namespace util="http://exist-db.org/xquery/util";
import module namespace xmldb="http://exist-db.org/xquery/xmldb";
declare function local:get-latest-created-document($collection-uri as xs:string) as map(*) {
if (xmldb:collection-available($collection-uri)) then
let $documents := xmldb:xcollection($collection-uri) ! util:document-name(.)
@joewiz
joewiz / frus-volume-titles.xq
Created November 8, 2017 18:44
Toward a compact form of FRUS series-wide compact form
xquery version "3.1";
element volumes {
let $vols := collection("/db/apps/frus/bibliography")/volume[publication-status eq "published"]
for $vol in $vols
let $vol-id := $vol/@id
let $title :=
(
$vol/title[@type eq "sub-series"],
$vol/title[@type eq "volume-number"],
@joewiz
joewiz / README.md
Last active February 13, 2018 14:01
Full text search of Chinese text, with eXist-db and Lucene

Full text search of Chinese text, with eXist-db and lucene

Note: This gist has been superseded by https://github.com/joewiz/exist-cjk but is left here should it be useful to anyone. Please post questions in an issue there.

This gist contains some sample files showing how to configure full text queries on Chinese text with eXist.

It assumes you have already installed eXist 3.5.0+.

Set up

@joewiz
joewiz / date-processing.xqm
Created October 18, 2017 21:49
Simple date processing, with XQuery
xquery version "3.1";
module namespace dp = "http://history.state.gov/ns/xquery/date-processing";
declare variable $dp:month-regex := "(January|February|March|April|May|June|July|August|September|October|November|December)";
declare variable $dp:day-regex := "(\d{1,2})(?:st|d|nd|rd|th)?";
declare variable $dp:regexes :=
map {
@joewiz
joewiz / list-abbreviations.xq
Last active October 19, 2017 14:54
List abbreviations in a text, with XQuery 3.1
xquery version "3.1";
(: Force oXygen to indent the output :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "xml";
declare option output:indent "yes";
(: Assumed context: you're running this in oXygen's XPath/XQuery Builder pane
: with an XML document open in the main editor :)
@joewiz
joewiz / try-catch-boilerplate.xq
Created October 12, 2017 17:46
XQuery 3.0 try/catch boilerplate, returning all error variables
xquery version "3.1";
try {
fn:error()
} catch * {
map {
"code": $err:code,
"description": $err:description,
"value": $err:value,
"module": $err:module,