Skip to content

Instantly share code, notes, and snippets.

View xquery's full-sized avatar

James Fuller xquery

View GitHub Profile
@joewiz
joewiz / generate-tsv.xq
Created April 28, 2015 17:21
Construct a tab-separated value (TSV) file and save it to the file system, with XQuery and EXPath File Module
xquery version "3.0";
(: Construct a tab-separated value (TSV) file and save it to the file system.
:
: This should work in any XQuery 3.0-enabled processor that supports the EXPath File
: Module.
:
: Tested in oXygen 16.1 in the "XPath/XQuery Builder" view, using the "Saxon-EE XQuery"
: engine, with "Enable XQuery 3.0 support" option selected (in the "Saxon-HE/PE/EE"
: portion of oXygen's preferences).
@ellispritchard
ellispritchard / README.md
Last active May 12, 2016 12:15
MarkLogic XQuery timezone conversion support: functions to convert times between named zones using the IANA Time Zone Database. Converts compiled tz database files for use with the conversion function.

MarkLogic Timezone support

Usage

timezone.xqy can convert between times in named timezones, using special TimeZoneInfo files produced from UNIX zoneinfo files, e.g. it allows you to look up the equivalent time in New York, based on a time in London.

tz:adjust-dateTime-to-timezone(xs:dateTime('2013-05-09T10:34:00+01:00'),'America/New_York')

=> xs:dateTime('2013-05-09T05:34:00-04:00')
@xquery
xquery / memoization.xqy
Created May 4, 2011 05:57
Inline caching (memoization) for higher order xquery functions
xquery version "1.0-ml";
(: xquery memoization example for use with MarkLogic :)
declare variable $cache := map:map();
declare function local:factorial($n as xs:integer) as xs:integer {
if ($n < 0) then
(0)
else if ($n = 0) then