Skip to content

Instantly share code, notes, and snippets.

@caschwartz
Last active December 21, 2015 14:48
Show Gist options
  • Select an option

  • Save caschwartz/6322052 to your computer and use it in GitHub Desktop.

Select an option

Save caschwartz/6322052 to your computer and use it in GitHub Desktop.
XQuery - Query to list unique PTS collection names (taken from MARC 730 fields)
xquery version "1.0-ml";
(: 8/21/13 Query to list unique PTS collection names (taken from MARC 730 fields) :)
declare namespace ia = "http://my.local.namespace";
declare namespace m = "http://www.loc.gov/MARC21/slim";
(: Finds unique collection names other than Benson and Torrance :)
let $collNames := fn:distinct-values(for $doc in fn:collection()[1 to 10000]
let $marc := $doc/ia:doc/ia:metadata/ia:marc/m:record
let $collections := $marc/m:datafield[@tag = "730"][@ind2 = " "]
for $collection in $collections
let $collectionString := fn:normalize-space($collection)
where fn:not(fn:matches($collectionString, "Benson|Torrance"))
(: Tests for keywords found in PTS collection names to filter out other values :)
and fn:matches($collectionString, "collection|library", "i")
(: Removes final period from collection names :)
return fn:replace($collectionString, "\.$", ""))
(: Creates alphabetic sequence of collection names before using a positional variable :)
let $sortedNames := for $collName in $collNames
order by $collName
return $collName
(: Return collection names as numbered list :)
for $sortedName at $count in $sortedNames
return <p>{$count}. {$sortedName}</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment