source: exist/trunk/xquery/moles2DC.xq @ 3118

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/moles2DC.xq@3158
Revision 3118, 5.3 KB checked in by lawrence, 12 years ago (diff)

Splitting out the (authoratative?) python xqueries into named
files within the new egg for exist (and other ndg utilities)

Line 
1(: Create a dublin core document from Moles documents in TargetCollection which have RepositoryID and LocalID :)
2import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
3import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
4declare default element namespace 'http://ndg.nerc.ac.uk/moles';
5declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
6declare namespace dc='http://purl.org/dc/elements/1.1/';
7declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc/';
8(:
9declare variable $targetCollection as xs:string {'/db/ndg_B_metadata'};
10declare variable $repositoryIdentifier as xs:string {'badc.nerc.ac.uk'};
11declare variable $localIdentifier as xs:string {'dataent_chablis'};
12:)
13
14declare variable $targetCollection as xs:string {'TargetCollection'};
15declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
16declare variable $localIdentifier as xs:string {'LocalID'};
17
18for $DE in collection($targetCollection)/dgMetadata/dgMetadataRecord[
19exists('dgDataEntity')
20and dgMetadataID/repositoryIdentifier=$repositoryIdentifier
21and dgMetadataID/localIdentifier=$localIdentifier]
22return
23element oai_dc:dc {
24attribute xsi:schemaLocation {'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'},
25element dc:title {string($DE/name)},
26element dc:type {'Dataset'},
27element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, $utillib:moles_id_separator, 'DC', $utillib:moles_id_separator, $DE/dgMetadataID/localIdentifier)},
28for $identifiers in $DE/(dgMetadataDescription/descriptionSection/descriptionOnlineReference | abstract/abstractOnlineReference)[
29exists(dgReferenceClass/dgValidTermID/ParentListID)
30and
31voclib:spot-vocab($voclib:ndg_online_reference_classes_vocab, dgReferenceClass/dgValidTermID/ParentListID)
32and
33dgReferenceClass/dgValidTerm='DataPage']
34return element dc:identifier {data($identifiers/dgSimpleLink/URI)},
35element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)},
36element dc:date
37{
38if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then
39for $updatedate in ($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)
40order by xs:date($updatedate)
41return data($updatedate[1])
42else
43string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate)
44},
45for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword[
46voclib:spot-vocab($voclib:cf_standard_names, dgValidTermID/ParentListID)
47or voclib:spot-vocab($voclib:gcmd_science_valids, dgValidTermID/ParentListID)
48or voclib:spot-vocab($voclib:gcmd_project_valids, dgValidTermID/ParentListID)
49or voclib:spot-vocab($voclib:iso_topic_list, dgValidTermID/ParentListID)
50or voclib:spot-vocab($voclib:bodc_parameter_usage_vocab, dgValidTermID/ParentListID)
51or voclib:spot-vocab($voclib:bodc_parameter_discovery_vocab, dgValidTermID/ParentListID)
52]/dgValidTerm)
53order by $StructuredKeyword
54return
55element dc:subject {string($StructuredKeyword)},
56
57for $StructuredKeyword1 in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[
58voclib:spot-vocab($voclib:gcmd_science_valids, dgValidTermID/ParentListID)
59or voclib:spot-vocab($voclib:gcmd_project_valids, dgValidTermID/ParentListID)
60or voclib:spot-vocab($voclib:bodc_parameter_usage_vocab, dgValidTermID/ParentListID)
61or voclib:spot-vocab($voclib:bodc_parameter_discovery_vocab, dgValidTermID/ParentListID)
62]/dgValidTerm)
63order by $StructuredKeyword1
64return
65element dc:subject  {string($StructuredKeyword1)},
66for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder
67order by $DataCreatorRole/startDate empty least
68return
69for $DataCreatorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
70[(dgMetadataID/schemeIdentifier='NDG-B0'
71and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
72and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
73return
74element dc:creator {
75if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then
76(string($DataCreatorRoleHolder/name))
77else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then
78(string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))))
79else ('empty content')
80},
81for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate='']
82order by $DataCuratorRole/startDate empty least
83return
84for $DataCuratorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
85[(dgMetadataID/schemeIdentifier='NDG-B0'
86and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
87and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
88return
89element dc:publisher {
90if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then
91(string($DataCuratorRoleHolder/name))
92else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then
93(string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))))
94else ('empty content')
95}
96}  (: </oai_dc:dc> :)
Note: See TracBrowser for help on using the repository browser.