Skip to content

Instantly share code, notes, and snippets.

View caschwartz's full-sized avatar

Christine Schwartz caschwartz

View GitHub Profile
@caschwartz
caschwartz / ead-subject-headings.xqy
Last active March 10, 2020 13:35
XQuery - Query to locate EAD documents with <controlaccess> element containing subject headings
xquery version "1.0-ml";
(: 8/6/12 Query to locate EAD documents that have a <controlaccess> element with subject headings. :)
declare namespace ead = "urn:isbn:1-931666-22-9";
for $doc in xdmp:directory("/EAD/")
let $controlAccess := $doc/ead:ead/ead:archdesc/ead:controlaccess[2] (: Second controlaccess element contains subjects :)
let $title := $doc/ead:ead/ead:eadheader/ead:filedesc/ead:titlestmt/ead:titleproper
return $controlAccess
xquery version "1.0-ml";
(: 8/29/18 Query used to add three attributes: type, integer, and id to new <relatedNumber> element :)
declare namespace ia = "http://digital.library.ptsem.edu/ia";
for $doc in collection("pts-journals")
let $vol-info := $doc/ia:doc/ia:metadata/ia:relatedItem/ia:volumeInfo
let $volume := $vol-info/ia:volume
@caschwartz
caschwartz / identify-duplicates.xqy
Last active May 19, 2017 15:38
Query McIntire audio recordings to identify duplicates based on recording date
xquery version "1.0-ml"; (: Delete/change XQuery version declaration if not a MarkLogic user :)
import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx-1.0-nodoc-2007-01.xqy";
declare namespace ia = "http://digital.library.ptsem.edu/ia";
let $rec-dates :=
for $doc in collection("media-available")
let $title := $doc/ia:doc/ia:metadata/ia:title
let $rec-date := $doc/ia:doc/ia:metadata/ia:recordingDate
@caschwartz
caschwartz / create-sequential-ids.xq
Last active October 25, 2016 18:49
XQuery - Query to create sequential journal article ids
(: 11/23/11 Cliff's Code - Sequential Article ID's :)
xquery version "1.0-ml";
declare namespace mets = "http://www.loc.gov/METS/";
for $doc in xdmp:directory("/METS/")
let $dmdSecs :=
for $dmdSec in $doc/mets:mets/mets:dmdSec
where $dmdSec//*:type = "Article"
@caschwartz
caschwartz / find-call-numbers.xq
Last active October 25, 2016 18:46
XQuery - Use cts:uris to find irregular call numbers in 090 fields in embedded MARCXML
xquery version "1.0-ml";
(: 2/23/11 Use MarkLogic function cts:uris to find irregular call numbers in the 090 field of MARCXML :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $uris := cts:uris((), "ascending")
for $uri in $uris[fn:position() = (50001 to fn:last())]
@caschwartz
caschwartz / add-sort-element-for-issues.xqy
Last active October 25, 2016 18:44
XQuery - Adds "sort" element to dmdSec of METS documents for journal issue numbers
xquery version "1.0-ml";
(: 12/1/11 Adds "sort" element to dmdSec of METS documents for issue numbers :)
declare namespace sort = "http://my.server/my.directory";
declare namespace mets = "http://www.loc.gov/METS/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
for $journal in xdmp:directory("/METS/")/mets:mets/mets:dmdSec[2]/mets:mdWrap/mets:xmlData
let $title := $journal/dc:format
@caschwartz
caschwartz / add-sort-elements.xq
Last active October 25, 2016 18:42
XQuery - Adds "sort" namespace to dmdSec of METS documents for volume and issue numbers
xquery version "1.0-ml";
(: 12/1/11 Adds "sort" elements to dmdSec of METS documents for volume and issue numbers :)
declare namespace sort = "http://my.local.namespace/sort";
declare namespace mets = "http://www.loc.gov/METS/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
for $journal in xdmp:directory("/METS/")/mets:mets/mets:dmdSec[2]/mets:mdWrap/mets:xmlData
let $title := $journal/dc:format
@caschwartz
caschwartz / normalize-title-list.xq
Last active October 25, 2016 18:38
XQuery - Query METS documents to normalize book title list
xquery version "1.0-ml";
(: 7/13/11 Working on browse book title list for Digital Library of AK :)
declare namespace METS = "http://www.loc.gov/METS/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
declare namespace html = "http://www.w3.org/1999/xhtml";
let $collection := fn:collection()
let $first-section := $collection/METS:mets/METS:dmdSec[1]
@caschwartz
caschwartz / get-copy-info.xqy
Created June 8, 2016 14:47
Function to get copy numbers from Ex Libris Voyager items record
(: Check for copy numbers in the items record :)
declare function mpm:get-copy-info($seq as xs:integer)
as node()*
{
let $records := xdmp:directory(concat("/Monographs/", $seq, "/"), "infinity")
let $items := $records/holdings/institution/holding/item (: May be more than one item record :)
for $item in $items
let $copy-info := $item/itemData[@name = "copy"]
return $copy-info
};
@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 ,