Last active
August 29, 2015 14:15
-
-
Save jindrichmynarz/3fe8392fe9ecfe0a5e3f to your computer and use it in GitHub Desktop.
MARCXML field and subfield frequencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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