Skip to content

Instantly share code, notes, and snippets.

@jindrichmynarz
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jindrichmynarz/3fe8392fe9ecfe0a5e3f to your computer and use it in GitHub Desktop.
Save jindrichmynarz/3fe8392fe9ecfe0a5e3f to your computer and use it in GitHub Desktop.
MARCXML field and subfield frequencies
xquery version "3.0";
declare default element namespace "http://www.loc.gov/MARC21/slim";
declare option saxon:output "omit-xml-declaration=yes";
declare option saxon:output "method=text";
declare variable $records := /collection/record;
declare variable $total := count($records);
string-join(
for $record in $records,
$field in $record/(controlfield|datafield),
$subfield allowing empty in $field/subfield/@code
group by $field_tag := $field/@tag, $subfield
let $count := count(distinct-values($record))
order by $count descending
return (
text{string-join((string($field_tag), $subfield, string(round($count div $total, 4))), ",")}
),
text{"
"}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment