source: TI07-MOLES/trunk/DublinCore/XQuery/NDG-DublinCore.xquery @ 2171

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/DublinCore/XQuery/NDG-DublinCore.xquery@2171
Revision 2171, 4.6 KB checked in by ko23, 13 years ago (diff)

Refactoring intermediate

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