source: TI07-MOLES/trunk/DIF/XQuery/DIF2MOLES.xquery @ 2192

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

Corrected MDIP deconstructors

Line 
1(: Version for one DIF per dgMetadata instance :)
2(: Note algoritm for creating non-pre-existing organisations :)
3(: dgPersons are not created as one can't tell automatically which are people and which are orgs, and orgs are simpler :) 
4import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
5import module namespace inputParse='http://ndg.nerc.ac.uk/xquery/lib/inputParse' at 'xmldb:exist:///db/xqueryLib/Utilities/inputParse_xquery_lib.xquery';
6declare default element namespace 'http://ndg.nerc.ac.uk/moles';
7declare namespace dif='http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
8declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
9
10(: Replacable parameters :)
11declare variable $targetCollection as xs:string {'TargetCollection'};
12declare variable $input_repository as xs:string {'Input_Repository_Code'};
13declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'};
14declare variable $input_entry_id as xs:string {'Input_Entry_ID'};
15declare variable $output_local_id as xs:string {'Output_LocalID'};
16
17for $DIF in collection($targetCollection)/dif:DIF[dif:Entry_ID=$input_entry_id]
18return
19element dgMetadata {
20element dgMetadataRecord {
21element dgMetadataID {
22element schemeIdentifier {'NDG-B0'},
23element repositoryIdentifier {$input_repository},
24if ($output_local_id != 'Output_LocalID') then
25element localIdentifier {$output_local_id}
26else
27element localIdentifier {escape-uri(string($DIF/dif:Entry_ID), true())}
28},
29element dgMetadataDescription {
30element metadataDescriptionID {
31element schemeIdentifier {'NDG-B0'},
32element repositoryIdentifier {$input_repository},
33if ($output_local_id != 'Output_LocalID') then
34element localIdentifier {concat('generated_desc-', $output_local_id)}
35else
36element localIdentifier {concat('generated_desc-', escape-uri(string($DIF/dif:Entry_ID), true()))}
37},
38element metadataDescriptionLastUpdated {current-date()}                 ,
39element abstract {
40element abstractText {string($DIF/dif:Summary)}
41}
42},
43element name {string($DIF/dif:Entry_Title)},
44element abbreviation {string($DIF/dif:Entry_Title)},
45element dgDataEntity {
46element dgDataSetType {''},
47element dgDataSummary {
48for $parameter in $DIF/dif:Parameters
49return
50element dgParameterSummary {
51element dgParameterValue {
52element dgValueDataParameter {
53element Value {''},
54element dgStandardUnit {
55element dgValidTerm {'dummy'},
56element dgValidTermID {
57element ParentListID {$voclib:unknown_vocab_id},
58element TermID {escape-uri('dummy unit', true())}
59}
60}
61}
62},
63element dgStdParameterMeasured {
64element dgValidTerm {
65concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)),
66if (exists($parameter/dif:Variable)) then
67concat(' > ', string($parameter/dif:Variable))
68else (),
69if (exists($parameter/dif:Detailed_Variable)) then
70concat(' > ', string($parameter/dif:Detailed_Variable))
71else ()
72},
73element dgValidTermID {
74element ParentListID {concat($voclib:gcmd_science_valids, '/current')},
75element TermID {escape-uri($parameter/dif:Category, true())}
76}
77},
78element ParameterName {
79concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)),
80if (exists($parameter/dif:Variable)) then
81concat(' > ', string($parameter/dif:Variable))
82else (),
83if (exists($parameter/dif:Detailed_Variable)) then
84concat(' > ', string($parameter/dif:Detailed_Variable))
85else ()
86},
87element ParameterAbbreviation {
88concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)),
89if (exists($parameter/dif:Variable)) then
90concat(' > ', string($parameter/dif:Variable))
91else (),
92if (exists($parameter/dif:Detailed_Variable)) then
93concat(' > ', string($parameter/dif:Detailed_Variable))
94else ()
95}
96},
97if (exists($DIF/dif:Spatial_Coverage) or exists($DIF/dif:Paleo_Temporal_Coverage) or exists($DIF/dif:Location) or exists($DIF/dif:Temporal_Coverage)) then
98element dgDataCoverage {
99if (exists($DIF/dif:Spatial_Coverage)  or exists($DIF/dif:Location))  then
100element dgSpatialCoverage {
101for $boundingbox in $DIF/dif:Spatial_Coverage[exists(dif:Northernmost_Latitude)
102and exists(dif:Southernmost_Latitude)
103and exists(dif:Easternmost_Longitude)
104and exists(dif:Westernmost_Longitude)]
105return
106element BoundingBox {
107element LimitNorth {data(inputParse:fix-coord($boundingbox/dif:Northernmost_Latitude))},
108element LimitSouth {data(inputParse:fix-coord($boundingbox/dif:Southernmost_Latitude))},
109element LimitWest {data(inputParse:fix-coord($boundingbox/dif:Westernmost_Longitude))},
110element LimitEast {data(inputParse:fix-coord($boundingbox/dif:Easternmost_Longitude))}
111},
112for $location in $DIF/dif:Location
113return
114element dgArea {
115element dgValidTerm {string($location)},
116element dgValidTermID {
117element ParentListID {concat($voclib:gcmd_location_valids, '/current')},
118element TermID {escape-uri($location, true())}
119}
120}
121}
122else (),
123if (exists($DIF/dif:Temporal_Coverage/dif:Start_Date) or exists($DIF/dif:Paleo_Temporal_Coverage/dif:Paleo_Start_Date) or exists($DIF/dif:Chronostratigraphic_Unit)) then
124element dgTemporalCoverage {
125for $temporalcoverage in $DIF/dif:Temporal_Coverage[exists(dif:Start_Date)]
126return
127element DateRange {
128element DateRangeStart {string($temporalcoverage/dif:Start_Date)},
129element DateRangeEnd {string($temporalcoverage/dif:Stop_Date)}
130},
131for $paleotemporalcoverage in $DIF/dif:Paleo_Temporal_Coverage[exists(dif:Paleo_Start_Date)]
132return
133element DateRange {
134element DateRangeStart {string($paleotemporalcoverage/dif:Paleo_Start_Date)},
135element DateRangeEnd {string($paleotemporalcoverage/dif:Paleo_Stop_Date)}
136},
137for $chronostratigraphic in $DIF/dif:Chronostratigraphic_Unit
138return
139element dgChronostratigraphicTerm {
140element dgValidTerm {string($chronostratigraphic)},
141element dgValidTermID {
142element ParentListID {concat($voclib:gcmd_chronostratigraphic_valids, '/current')},
143element TermID {escape-uri($chronostratigraphic, true())}
144}
145}
146}
147else ()
148}
149else ()
150},
151element dgDataRoles {
152if (exists($DIF/dif:Data_Set_Citation/dif:Dataset_Creator)) then
153element dgDataCreator {
154element dgMetadataID {
155element schemeIdentifier {'NDG-B0'},
156element repositoryIdentifier {$input_repository},
157if ($output_local_id != 'Output_LocalID') then
158element localIdentifier {concat('generated_creator-', $output_local_id)}
159else
160element localIdentifier {concat('generated_creator-', escape-uri(string($DIF/dif:Entry_ID), true()))}
161},
162element roleName {'Data Creator'},
163element abbreviation {'Creator'},
164for $creatorID in $DIF/dif:Data_Set_Citation/dif:Dataset_Creator
165return
166element dgRoleHolder {
167element dgOrganisationID {
168element schemeIdentifier {'NDG-B0'},
169element repositoryIdentifier {$input_repository},
170if ($output_local_id != 'Output_LocalID') then
171element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())}
172else
173element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())}
174},
175element startDate {current-date()}
176}
177}
178else if (exists($DIF/dif:Originating_Center)) then
179element dgDataCreator {
180element dgMetadataID {
181element schemeIdentifier {'NDG-B0'},
182element repositoryIdentifier {$input_repository},
183if ($output_local_id != 'Output_LocalID') then
184element localIdentifier  {escape-uri(concat('generated_creator-', $output_local_id), true())}
185else
186element localIdentifier  {escape-uri(concat('generated_creator-', data($DIF/dif:Entry_ID)), true())}
187},
188element roleName {'Data Creator'},
189element abbreviation {'Creator'},
190for $creatorID in $DIF/dif:Originating_Center
191return
192element dgRoleHolder {
193element dgOrganisationID {
194element schemeIdentifier {'NDG-B0'},
195element repositoryIdentifier {$input_repository},
196if ($output_local_id != 'Output_LocalID') then
197element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())}
198else
199element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())}
200},
201element startDate {current-date()}
202}
203}
204else (),
205element dgDataCurator {
206element dgMetadataID {
207element schemeIdentifier {'NDG-B0'},
208element repositoryIdentifier {$input_repository},
209if ($output_local_id != 'Output_LocalID') then
210element localIdentifier  {escape-uri(concat('generated_curator-', $output_local_id), true())}
211else
212element localIdentifier  {escape-uri(concat('generated_curator-', data($DIF/dif:Entry_ID)), true())}
213},
214element roleName {'Data Curator'},
215element abbreviation {'Curator'},
216element dgRoleHolder {
217element dgOrganisationID {
218element schemeIdentifier {'NDG-B0'},
219element repositoryIdentifier {$input_repository},
220element localIdentifier {$input_repository_local}
221},
222element startDate {current-date()}
223}
224}
225}
226},
227element dgStructuredKeyword {
228element dgValidTerm {'d2b converted record'},
229element dgValidTermID {
230element ParentListID {$voclib:unknown_vocab_id},
231element TermID {'d2b'}
232}
233},
234for $structuredKeywords in $DIF/dif:Keyword
235return
236element dgStructuredKeyword {
237element dgValidTerm {string($structuredKeywords)},
238element dgValidTermID {
239if ($structuredKeywords='MDIP' or $structuredKeywords='NERC' or $structuredKeywords='NERC_DDC') then
240element ParentListID {concat(voclib:ndg_data_provider_vocab, '/current')}
241else
242element ParentListID {$voclib:unknown_vocab_id}
243,
244element TermID {escape-uri($structuredKeywords, true())}
245}
246},
247for $structuredKeywords in $DIF/dif:ISO_Topic_Category
248return
249element dgStructuredKeyword {
250element dgValidTerm {string($structuredKeywords)},
251element dgValidTermID {
252element ParentListID {concat($voclib:iso_topic_list, '/current')},
253element TermID {escape-uri($structuredKeywords, true())}
254}
255},
256if (exists($DIF/dif:DIF_Creation_Date) or exists($DIF/dif:Last_DIF_Revision_Date)) then
257element dgMetadataProvenance {
258if (exists($DIF/dif:DIF_Creation_Date)) then
259element RecordCreation {
260element CreatedDate {
261if (string($DIF/dif:DIF_Creation_Date) castable as xs:date) then
262string($DIF/dif:DIF_Creation_Date) cast as xs:date
263else (current-date())
264},
265element CreatedBy {$input_repository}
266}
267else
268element RecordCreation {
269element CreatedDate {current-date()},
270element CreatedBy {'MOLES Import'}
271},
272if (exists($DIF/dif:Last_DIF_Revision_Date)) then
273element RecordUpdate {
274element UpdateDate {
275if (string($DIF/dif:Last_DIF_Revision_Date) castable as xs:dateTime) then
276string($DIF/dif:Last_DIF_Revision_Date) cast as xs:dateTime
277else (current-dateTime())
278},
279element UpdatedBy {$input_repository}
280}
281else ()
282}
283else ()
284} (: </dgMetadataRecord>:),
285for $creator in distinct-values($DIF/(dif:Data_Set_Citation/dif:Dataset_Creator | dif:Originating_Center))
286return
287element dgOrganisation {
288element dgMetadataID {
289element schemeIdentifier {'NDG-B0'},
290element repositoryIdentifier {$input_repository},
291if ($output_local_id != 'Output_LocalID') then
292element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creator), '-', $output_local_id), true())}
293else
294element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creator), '-', data($DIF/dif:Entry_ID)), true())}
295},
296element name {string($creator)},
297element abbreviation {string($creator)},
298element contactDetails {''}
299}
300} (:    </dgMetadata> :)
Note: See TracBrowser for help on using the repository browser.