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

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

XQuery refactoring process - part one...

  • 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 {'/db/ndg_B_metadata'};
7declare variable $gcmd_science_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html'};
8declare variable $gcmd_project_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html'};
9declare variable $cf_standard_names as xs:string {'http://www.cgd.ucar.edu/cms/eaton/cf-metadata/standard_name.html'};
10declare variable $iso_topic_list as xs:string {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'};
11
12for $DE in collection($targetCollection)/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='badc.nerc.ac.uk' and dgMetadataID/localIdentifier='dataent1']
13return
14element oai_dc:dc {
15        attribute xsi:schemaLocation {'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'},
16        element dc:title {string($DE/name)},
17        element dc:type {'Dataset'},
18        element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, ':DC:', $DE/dgMetadataID/localIdentifier)},
19        element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)},
20        element dc:date
21                {
22                if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then
23                        for $updatedate in ($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)
24                                order by xs:dateTime($updatedate)
25                        return data($updatedate[1])
26                else
27                        string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate)
28                },
29        for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword [dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids or dgValidTermID/ParentListID=$iso_topic_list ]//dgValidTerm)
30                order by $StructuredKeyword
31                return
32                element dc:subject {string($StructuredKeyword)},
33       
34        for $StructuredKeyword1 in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids]//dgValidTerm)
35                order by $StructuredKeyword1
36        return
37                element dc:subject  {string($StructuredKeyword1)},
38        for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder
39                order by $DataCreatorRole/startDate empty least
40        return
41                for $DataCreatorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
42                        [(dgMetadataID/schemeIdentifier='NDG-B0'
43                        and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
44                        and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
45                return
46                        element dc:creator {
47                                if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then
48                                        (string($DataCreatorRoleHolder/name))
49                                else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then
50                                        (string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))))
51                                else ('empty content')
52                        },
53        for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate='']
54                order by $DataCuratorRole/startDate empty least
55        return
56                for $DataCuratorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
57                        [(dgMetadataID/schemeIdentifier='NDG-B0'
58                        and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
59                        and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
60                return
61                        element dc:publisher {
62                                if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then
63                                        (string($DataCuratorRoleHolder/name))
64                                else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then
65                                        (string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))))
66                                else ('empty content')
67                        }
68}  (: </oai_dc:dc> :)
Note: See TracBrowser for help on using the repository browser.