source: TI07-MOLES/trunk/DIF/XQuery/NDG-DIF.xquery @ 2056

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

Second element Address case fixed

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
2declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
3declare namespace moles='http://ndg.nerc.ac.uk/moles';
4declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
5
6for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[
7        exists('moles:dgDataEntity')
8        and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
9        and moles:dgMetadataID/moles:repositoryIdentifier='grid.bodc.nerc.ac.uk'
10        and moles:dgMetadataID/moles:localIdentifier='HGFS3751']
11return
12    element DIF {
13        attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},
14        element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, ':DIF:', $DE/moles:dgMetadataID/moles:localIdentifier)},
15        element Entry_Title {string($DE/moles:name)},
16        element Data_Set_Citation {
17            for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1]
18                return
19                    for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
20                               and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier
21                               and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)]
22                        return
23                            element Data_Creator {
24                                if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then
25                                    string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))
26                                else
27                                   string($DataCreatorRoleHolder/moles:abbreviation)
28                                },
29            element Dataset_Title {string($DE/moles:name)}
30        },
31        for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | moles:dgStdParameterMeasured)[moles:dgValidTermID/moles:ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' and moles:ListLevel = 0])
32                return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then
33                    element Parameters {
34                        element Category {string($StructuredKeyword/*/moles:dgValidTerm)},
35                        if (exists($StructuredKeyword//moles:dgValidSubterm)
36                                and $StructuredKeyword//moles:dgValidSubterm != ''
37                                and $StructuredKeyword//moles:dgValidSubterm != ' ') then
38                        for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)]
39                            where exists($Subterm/moles:dgValidSubterm)
40                            order by $Subterm/moles:ListLevel
41                                return
42                                        if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
43                                        else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
44                                        else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
45                                        else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
46                                        else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
47                        else()
48                    }
49                else(),
50        for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[moles:dgValidTermID/moles:ParentListID='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'])
51            return
52                element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)},
53        for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[
54        moles:dgValidTermID/moles:ParentListID!='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' 
55        and
56        moles:dgValidTermID/moles:ParentListID!='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode' 
57        ]/moles:dgValidTerm)
58        return element Keyword {string($Keyword)},
59        for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID) 
60        return
61            element Sensor_Name {
62                for $DepDPTAbbrev in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:abbreviation))
63                    return element Short_Name {data($DepDPTAbbrev)},
64                for $DepDPTName in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:name))
65                    return element Long_Name {data($DepDPTName)}
66                },
67        for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID)
68        return
69            element Source_Name {
70                for $DepObsStnAbbrev in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:abbreviation))
71                    return element Short_Name {data($DepObsStnAbbrev)},
72                for $DepObsStnName in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:name))
73                    return element Long_Name {data($DepObsStnName)}
74                },
75        for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange)
76                return
77                    element Temporal_Coverage
78                        {
79                        element Start_Date {data($TemporalRange/moles:DateRangeStart)},
80                        element End_Date {data($TemporalRange/moles:DateRangeEnd)}
81                        },
82        for $TemporalTerm in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea/moles:dgValidTerm)
83                return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},
84        for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure)
85                return element Data_Set_Progress {data($Data_Set_Progress)},
86        for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox)
87        return
88            element Spatial_Coverage {
89                    element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)},
90                    element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)},
91                    element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)},
92                    element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)}
93                },
94        for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[moles:dgValidTermID/moles:ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_locations.html'])
95                return element Location {$Location},
96        for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID)
97        return
98            element Project {
99                for $DepActAbbrev in distinct-values(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:abbreviation)
100                    return
101                        element Short_Name {data($DepActAbbrev)},
102                for $DepActName in distinct-values(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:name)
103                    return
104                        element Long_Name {data($DepActName)}
105                },
106        if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then
107                for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule
108                    return
109                                element Access_Constraints {
110                                if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then
111                                    concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ')
112                                else (),
113                                if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then
114                                    concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true()))
115                                else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then
116                                    data($DG/moles:accessControlPolicy/moles:accessControlPolicyText)
117                                 else
118                                     for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition
119                                     return
120                                         if (exists($securityCondition/moles:conditionExplanationText)) then
121                                             concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText))
122                                         else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority))
123                            }
124                else (),
125        if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then
126                for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
127                    order by $DataCreatorRole/moles:startDate empty least
128                            return
129                                for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson)
130                                                [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
131                                                and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier
132                                                and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)]
133                                return
134                                        element Originating_Center {
135                                        if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then
136                                                (string($DataCreatorRoleHolder/moles:name))
137                                        else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then
138                                                (string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))))
139                                        else ('empty content')
140                                }
141        else (),
142        for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate='']
143            return
144                for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
145                   and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier
146                   and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)]
147                    return
148                        element Data_Center {
149                        element Data_Center_Name {
150                                element Short_Name {
151                                    if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
152                                    string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))
153                            else
154                                string($DataCuratorRoleHolder/moles:abbreviation)
155                            },
156                        element Long_Name {
157                                if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
158                                    string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))
159                                else string($DataCuratorRoleHolder/moles:name)
160                            }
161                        },
162                        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then
163                                element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)}
164                        else (),
165                        for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID
166                        return
167                            element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, ':', $DGID/moles:schemeIdentifier, ':', $DGID/moles:localIdentifier)},
168                        element  Personnel {
169                                element Role {'Data Center Contact'},
170                                if (exists($DataCuratorRoleHolder/name/knownAs)) then
171                                    element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)}
172                                else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
173                                    element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)}
174                                 else (),                                       
175                                 element Last_Name {
176                                          if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then
177                                              string($DataCuratorRoleHolder/moles:name/moles:familyName)
178                                    else string($DataCuratorRoleHolder/moles:name)
179                                    },
180                                if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then
181                                    element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)}
182                                else
183                                    if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then
184                                            (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)})
185                                        else (),
186                                if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then
187                                    element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)}
188                                else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then
189                                            element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}
190                                 else (),
191                                if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then
192                                    element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)}
193                                else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then
194                                            element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}
195                                        else (),
196                                if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then
197                                    element Contact_Address {
198                                        for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline
199                                            return element Address {data($addressline)},
200                                                        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then
201                                        element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}
202                                    else (),
203                                    if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then
204                                        element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)}
205                                    else (),
206                                     if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then
207                                         element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)}
208                                     else ()
209                                     }
210                                else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then
211                                    element Contact_Address {
212                                        for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline
213                                            return element Address {data($addressline)},
214                                                            if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then
215                                            element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}
216                                        else (),
217                                        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then
218                                            element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)}
219                                        else (),
220                                         if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then
221                                             element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)}
222                                         else ()
223                                     }
224                                else ()
225                                 }
226                        },
227        element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)},
228        element Related_URL  {
229            element URL_Content_Type {'NDG_B_SERVICE'},
230            element URL {data($DE/moles:dgMetadataID/moles:repositoryIdentifier)},
231            element Description {'The NDG service for browsing metadata.'}
232            },
233        for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule
234            return
235                if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then
236                    (element Related_URL {
237                            element URL_Content_Type {'NDG_A_SERVICE'},
238                            if (exists($DG/instance/URI)) then
239                                element URL {escape-uri($DG/instance/URI, true())}
240                            else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
241                                element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}
242                            else ($DG/moles:dataModelID/moles:repositoryIdentifier),
243                            element Description {'The NDG service delivering data via NDG A metadata.'}
244                        },
245                   element Related_URL {
246                            element URL_Content_Type {'GET DATA > CSML'},
247                            if (exists($DG/instance)) then
248                                element URL {escape-uri($DG/instance/URI, true())}
249                            else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
250                                element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())}
251                            else (),
252                            element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'}
253                        })
254                else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then
255                        (element Related_URL {
256                                   element URL_Content_Type {'NDG_A_SERVICE'},
257                            if (exists($DG/instance)) then
258                                element URL {escape-uri($DG/instance/URI, true())}
259                            else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
260                                element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}
261                            else (),
262                            element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}
263                            },
264                        element Related_URL {
265                            element URL_Content_Type {'GET DATA > DX'},
266                            if (exists($DG/instance)) then
267                                element URL {escape-uri($DG/instance/URI, true())}
268                            else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
269                                element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}
270                            else (),
271                            element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}
272                            })
273                else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then
274                    element Related_URL {
275                            element URL {data($DG/moles:instance/moles:URI)},
276                            if (exists($DG/moles:instance/moles:instanceComment)) then
277                                    element Description {data($DG/moles:instance/moles:instanceComment)}           
278                            else
279                                    element Description {'URL to aid in delivering data. Note that this may point directly to the data or, more likely, point to the web site of the curator.'}
280                            }
281            else (),
282            for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)
283            return
284                    element Related_URL {
285                            element URL {data($RelURL_Desc)},
286                            element Description {concat(data($RelURL_Desc/moles:name), ' - ', data($RelURL_Desc/moles:notes))}             
287                         },
288        element Metadata_Name {'[CEOS IDN DIF]'},
289        element Metadata_Version {'9.4'},
290        if  (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then
291                element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)}
292        else (),
293        for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate
294        return 
295            element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))},
296        if  (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then
297                element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)}
298        else ()
299        }
Note: See TracBrowser for help on using the repository browser.