-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmods-to-dc.xqy
148 lines (134 loc) · 4.56 KB
/
mods-to-dc.xqy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
xquery version "1.0";
(:
: Module Name: MODS to DC
: Module Version: 1.0
: Date: September, 2007
: Copyright: Michael J. Giarlo and Winona Salesky
: XQuery Specification: November 2005
: Module Overview: extracts Dublin Core elements from MODS records
:)
(:~
: Extracts Dublin Core elements from MODS records
:
: @author Michael J. Giarlo
: @author Winona Salesky
: @since September, 2007
: @version 1.0
:)
module namespace mods-to-dc = 'http://diglib.princeton.edu/ns/xquery/mods-to-dc';
declare default function namespace 'http://diglib.princeton.edu/ns/xquery/mods-to-dc';
declare namespace mods = 'http://www.loc.gov/mods/v3';
declare namespace dc = 'http://purl.org/dc/elements/1.1/';
(:~
: Get titles from MODS record and wrap them in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-title($_record) {
for $titleInfo in $_record/mods:titleInfo
let $title := $titleInfo/mods:title
let $subtitles := if (fn:empty($titleInfo/mods:subTitle)) then ()
else
for $subtitle in $titleInfo/mods:subTitle
return fn:string($subtitle)
return
<dc:title>{ fn:string-join((fn:string($title), $subtitles), " : ") }</dc:title>
};
(:~
: Get descriptions from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-description($_record) {
for $description in $_record//mods:note/descendant-or-self::*/text() | $_record//mods:abstract/descendant-or-self::*/text()
return
<dc:description>{ $description }</dc:description>
};
(:~
: Get dates from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-date($_record) {
for $date in $_record//mods:date | $_record//mods:dateCreated | $_record//mods:dateIssued
return
<dc:date>{ fn:string($date) }</dc:date>
};
(:~
: Get identifiers from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-identifier($_record) {
for $identifier in $_record/mods:identifier/text()
return
<dc:identifier>{ $identifier }</dc:identifier>
};
(:~
: Get relations from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-relation($_record) {
for $relatedItem in $_record/mods:relatedItem[fn:exists(child::mods:identifier)]
let $relation := fn:string($relatedItem/@type)
let $identifier := $relatedItem/mods:identifier/text()
return
<dc:relation>{ fn:concat($relation, " of ", $identifier) }</dc:relation>
};
(:~
: Get creators from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-creator($_record) {
if (fn:exists($_record//mods:name[mods:role/mods:roleTerm/text()='creator' or mods:role/mods:roleTerm/text()='photographer'])) then
for $creator in get-names($_record//mods:name[mods:role/mods:roleTerm/text()='creator' or mods:role/mods:roleTerm/text()='photographer'])
return
<dc:creator>{ fn:string($creator) }</dc:creator>
else
()
};
(:~
: Get contributors from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-contributor($_record) {
for $contributor in get-names($_record//mods:name[mods:role/mods:roleTerm/text()='contributor'])
return
<dc:contributor>{ fn:string($contributor) }</dc:contributor>
};
(:~
: Get subjects from MODS record and wrap it in Dublin Core
:
: @param $_record a MODS XML doc
: @return Dublin Core XML
:)
declare function get-subject($_record) {
let $subjects := $_record//mods:subject/descendant::*[fn:local-name() != 'namePart']/text() | $_record//mods:genre/descendant-or-self::*/text()
let $names := $_record//mods:subject/mods:name
let $subjectsWithName := fn:insert-before($subjects, 1, get-names($names))
for $subject in fn:distinct-values($subjectsWithName)
return
<dc:subject>{ fn:string($subject) }</dc:subject>
};
(:~
: Extract names from any MODS element (a helper function)
:
: @param $_record a sequence of mods:name elements
: @return string representing a composed name
:)
declare function get-names($_names) {
for $name in $_names
let $nameParts := $name/mods:namePart/text()
let $dcName := fn:string-join($nameParts, ", ")
return $dcName
};