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

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

Index prototype

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