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 / latest-package-versions-csv.xq
Last active January 12, 2023 19:02
Generate a CSV containing the latest versions of packages for different
xquery version "3.1";
import module namespace versions="http://exist-db.org/apps/public-repo/versions" at "/db/apps/public-repo/modules/versions.xqm";
let $exist-versions := ("4.11.0", "5.5.1", "6.1.0")
let $abbrevs := ("shared-resources", "dashboard", "doc", "eXide", "functx", "fundocs", "markdown", "monex", "usermanager")
let $header-row := ("package", $exist-versions ! ("eXist " || .)) => string-join(", ")
let $body-rows :=
for $abbrev in $abbrevs
let $packages := doc("/db/apps/public-repo-data/metadata/package-groups.xml")//package-group[abbrev = $abbrev]//package
@joewiz
joewiz / list-packages.xq
Last active January 3, 2023 17:50
List EXPath Packages installed on an eXist-db system
xquery version "3.1";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace pkg="http://expath.org/ns/pkg";
declare option output:method "html";
declare option output:html-version "5.0";
declare option output:media-type "text/html";
declare function local:sort-packages($packages as element(pkg:package)*) as element(pkg:package)* {
@joewiz
joewiz / populate-github-issue.xq
Last active December 19, 2022 20:44
Populate version info for the eXist issue tracker
xquery version "3.1";
(: Note: the environment-variable functions only work if the user running the query has DBA access :)
(: Probe available environment variables with the following query :)
(:
map:merge(
available-environment-variables() ! map:entry(., environment-variable(.))
),
:)
@joewiz
joewiz / strip-diacritics.xq
Last active October 22, 2022 14:42
Strip diacritics, with XQuery
xquery version "3.1";
declare function local:strip-diacritics($string as xs:string) as xs:string {
$string
=> normalize-unicode("NFD")
=> replace("\p{IsCombiningDiacriticalMarks}", "")
};
declare function local:inspect-diacritics($string as xs:string) as element() {
let $normalized := normalize-unicode($string, "NFD")
xquery version "3.0";
module namespace r = "http://joewiz.org/ns/xquery/roman-numerals";
(: Converts standard Roman numerals to integers.
: Handles additive and subtractive but not double subtractive.
: Case insensitive.
: Doesn't attempt to validate a numeral other than a naïve character check.
: See discussion of standard modern Roman numerals at:
: http://en.wikipedia.org/wiki/Roman_numerals.
@joewiz
joewiz / entities.xqm
Last active August 9, 2022 16:00
Look up HTML character entities and convert references to XML-compatible characters in XQuery
xquery version "3.1";
(:~ A module containing a lookup table, in the form of a map, for HTML entities
: that aren't defined in XML, and a function for converting HTML entities in
: strings to the appropriate characters. Look up characters via map lookup:
:
: $entities:entities?ograve?character => ò
:
: @author Joe Wicentowski
: @see https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Character_entity_references_in_HTML
@joewiz
joewiz / yaml-to-xml.xq
Created August 22, 2016 21:55
Convert YAML to XML, with XQuery
xquery version "3.0";
(: doesn't support YAML indentation yet - just a start :)
declare function local:process-yaml-value($value) {
let $single-quote := "^'(.+)'$"
let $double-quote := '^"(.+)"$'
return
if (matches($value, $single-quote) or matches($value, $double-quote)) then
let $pattern := "^['""](.+)['""]$"
@joewiz
joewiz / 01-levenshtein-distance.xq
Last active July 5, 2022 17:18
Calculate Levenshtein Distance, using XQuery
xquery version "3.1";
(:~
Calculate Levenshtein Distance, using XQuery
@author Guillaume Mella
@see http://apps.jmmc.fr/~mellag/xquery/levenshtein/2018/01/19/xquery-levenshtein-distance/
:)
declare function local:levenshtein-distance($string1 as xs:string?, $string2 as xs:string?)
as xs:integer
@joewiz
joewiz / README.md
Last active June 24, 2022 21:08
A report showing function signature mismatches in eXist's implementation of the XPath & XQuery functions & operators spec
@joewiz
joewiz / 01-generate-function-signatureTests.xq
Last active June 24, 2022 21:08 — forked from dizzzz/functionSignatureTests.xquery
A script to generate function-signature-tests for xquery functions in eXist-db
xquery version "3.1";
declare namespace fos="http://www.w3.org/xpath-functions/spec/namespace";
declare function local:writeHeader() as xs:string {
'
xquery version "3.1";
module namespace xqfunctions="http://exist-db.org/xquery/test/xqfunctions";