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

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

Update namespaceadder and DIF output support

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