Skip to content

Instantly share code, notes, and snippets.

View caschwartz's full-sized avatar

Christine Schwartz caschwartz

View GitHub Profile
@caschwartz
caschwartz / replace-order-attributes.xqy
Last active October 5, 2015 01:17
XQuery - Query to replace ORDER attribute numbers in METS documents
xquery version "1.0-ml";
(: 1/26/12 Query to replace ORDER attribute numbers for third-level divs in structMap :)
declare namespace mets = "http://www.loc.gov/METS/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $divsNumTwo := let $doc := fn:doc("/new-divs/Kuyper365-370.xml")
@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 / find-duplicate-titles.xqy
Last active October 5, 2015 09:57
XQuery - Query retrieves all duplicate titles with multiple volumes
xquery version "1.0-ml";
(: 5/23/12 This query retrieves all duplicate titles (with multiple volumes) from MARCXML records in database :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
fn:distinct-values(
@caschwartz
caschwartz / find-collection-headings.xqy
Last active October 5, 2015 17:27
Use cts:uris to query 730 fields for local collection headings in MARCXML
xquery version "1.0-ml";
(: 3/2/12 Use MarkLogic function cts:uris to query 730 fields for local collection headings in embedded MARCXML :)
declare namespace ia = "http://my.server/my.directory";
declare namespace m = "http://www.loc.gov/MARC21/slim";
let $values := fn:distinct-values(let $uris := cts:uris((), "ascending")
for $uri in $uris [fn:position() = (50001 to fn:last())]
@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-type-attributes.xqy
Last active October 5, 2015 17:28
XQuery - Query to add TYPE attributes for incomplete items in METS documents
xquery version "1.0-ml";
(: 3/8/12 Query to add TYPE attributes for incomplete items in METS documents :)
declare namespace mets = "http://www.loc.gov/METS/";
let $doc := fn:doc("/METS/Kuyper128.xml")
let $seriesNum := "128" (: Series number for incomplete items :)
let $divs := $doc/mets:mets/mets:structMap//mets:div (: Will work with any div at any level in the hierarchy :)
@caschwartz
caschwartz / get-language-text.xqy
Last active October 5, 2015 17:28
Query language elements in MODS documents and XML version of MARC Code List for Languages
xquery version "1.0-ml";
(: Query language elements in MODS documents and XML version of Library of Congress MARC Code List for Languages :)
declare namespace mods = "http://www.loc.gov/mods/v3";
declare namespace cd = "info:lc/xmlns/codelist-v1";
let $docs := xdmp:directory("/mods/", "infinity")
for $doc in fn:subsequence($docs, 1, 4)//mods:mods/mods:language
let $text := fn:doc("/marc-languages.xml")/cd:codelist/cd:languages/cd:language[cd:code = $doc/mods:languageTerm]/cd:name
@caschwartz
caschwartz / split-xml-file.xqy
Last active October 5, 2015 17:28
Query xml and split into separate files
xquery version "1.0-ml";
(: 6/8/11 Query Endnote xml and split into separate files :)
declare namespace functx = "http://www.functx.com";
declare function functx:pad-integer-to-length
( $integerToPad as xs:anyAtomicType? ,
$length as xs:integer ) as xs:string {
if ($length < string-length(string($integerToPad)))
@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 / 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"