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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/moles2DC.xq@4326
Revision 3841, 5.4 KB checked in by cbyrom, 12 years ago (diff)

Various updates to the xquery files - to remove usage of invalid specs
and dependency on obsolete function calls. Also add the inputParse_xquery_lib.xquery
file - referenced from the xquery files but not currently included in codebase.
NB, changes made to allow use of Saxon java library to do xqueries - to
remove the need for the discovery service eXist DB.

  • NB, also changes tested by comparing saxon transforms to eXist ones; these

were found to be identical.

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