Skip to content

Instantly share code, notes, and snippets.

View caschwartz's full-sized avatar

Christine Schwartz caschwartz

View GitHub Profile
@caschwartz
caschwartz / fizzbuzz.xqy
Created May 28, 2014 14:46
FizzBuzz in XQuery
xquery version "1.0-ml";
(: FizzBuzz puzzle :)
for $num in (1 to 100)
return
if ($num mod 3 = 0 and $num mod 5 = 0) then
"FizzBuzz"
else if ($num mod 3 = 0) then
"Fizz"
@caschwartz
caschwartz / build-number-sequence.xqy
Created May 8, 2014 14:52
XQuery - Build a sequence of numbers and count the number of items in the sequence
xquery version "1.0-ml";
(: 5/8/14 Build a sequence of numbers and count the number of items in the sequence :)
fn:count(let $unprocessedfootage := "10-17"
let $firstNum := xs:integer(fn:substring-before($unprocessedfootage, "-"))
let $lastNum := xs:integer(fn:substring-after($unprocessedfootage, "-"))
return for $box in ($firstNum to $lastNum)
return $box)
xquery version "1.0-ml";
(: 12/9/13 Query newly imported Benson collection books for names :)
declare namespace ia = "http://my.namespace/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
for $doc in fn:collection("Benson")
let $name := fn:normalize-space($doc/ia:doc/ia:metadata/ia:name)
@caschwartz
caschwartz / mets-add-type-attributes.xqy
Created April 7, 2014 19:16
XQuery - Query to add TYPE attributes for incomplete items
xquery version "1.0-ml";
(: 3/8/12 Query to add TYPE attributes for incomplete items in the kuyper-dl database :)
declare namespace mets = "http://www.loc.gov/METS/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
fn:distinct-values(
for $doc in fn:collection()
xquery version "1.0-ml";
(: This query finds properties information :)
declare namespace ia = "http://my.namespace/ia";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $docs := xdmp:directory("/ia-xml/1/", "infinity")
for $doc in $docs
@caschwartz
caschwartz / change-namespace.xqy
Created January 6, 2014 16:16
XQuery - Using Priscilla Walmsley's function, this query puts the root node and all descendant elements in the MARCXML namespace
xquery version "1.0-ml";
(: 1/6/14 Using Priscilla Walmsley's function, this query puts the root node and all descendant elements in the MARCXML namespace :)
declare namespace m = "http://www.loc.gov/MARC21/slim";
declare namespace functx = "http://www.functx.com";
declare function functx:change-element-ns-deep
( $nodes as node()* ,
$newns as xs:string ,
@caschwartz
caschwartz / correct-capitalization.xqy
Created December 10, 2013 22:00
XQuery - Corrected capitalization for collection headings in MODS documents
xquery version "1.0-ml";
(: Fix capitalization of collection titles ("inventory" database) :)
declare namespace mods = "http://www.loc.gov/mods/v3";
fn:distinct-values(
for $doc in fn:collection("MODS")
let $collection-title := $doc/mods:modsCollection/mods:mods/mods:titleInfo[@type="uniform"]
@caschwartz
caschwartz / edition-statements.xqy
Created November 14, 2013 18:39
XQuery - Query to create title list of (one volume) monographs with edition statements (using one of Priscilla Walmsley's functx XQuery functions
xquery version "1.0-ml";
(: 11/6/13 Query to create title list of (one volume) monographs with edition statements (using one of Priscilla Walmsley's functx XQuery functions :)
declare namespace ia = "http://my.local.namespace";
declare namespace m = "http://www.loc.gov/MARC21/slim";
declare namespace functx = "http://www.functx.com";
declare function functx:non-distinct-values
( $seq as xs:anyAtomicType* ) as xs:anyAtomicType* {
@caschwartz
caschwartz / change-superscript-to-ascii.xqy
Last active December 28, 2015 08:19
XQuery - Query to isolate superscript numbers and change to ASCII in the <tei:hi> element for TEI metadata
xquery version "1.0-ml";
(: 11/4/13 Query to isolate the superscript numbers and change to ASCII numbers in the <tei:hi> element :)
declare namespace tei = "http://www.tei-c.org/ns/1.0";
for $doc in fn:collection()
let $superNums := $doc//tei:hi[@rend = "super"]
for $superNum in $superNums
@caschwartz
caschwartz / add-xml-comments.xqy
Last active December 28, 2015 08:19
XQuery - Query to locate and comment out the empty MODS titleInfo elements using MarkLogic xdmp:node-replace()
xquery version "1.0-ml";
(: 11/13/13 Query to locate and comment out empty MODS titleInfo elements :)
declare namespace mods = "http://www.loc.gov/mods/v3";
for $doc in xdmp:directory("/MODS/", "infinity")
let $titles := $doc/mods:modsCollection/mods:mods/mods:titleInfo
for $title in $titles