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

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

d2b* DIF deconstruction update

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 {data($DIF/dif:Entry_ID)}
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 {string($parameter/dif:Category)},
65element dgValidTermID {
66element ParentListID {concat($voclib:gcmd_science_valids_categories, '/current')},
67element TermID {escape-uri($parameter/dif:Category, true())}
68},
69element dgValidSubterm {
70element dgValidTerm {string($parameter/dif:Topic)},
71element dgValidTermID {
72element ParentListID {concat($voclib:gcmd_science_valids_topics, '/current')},
73element TermID {escape-uri($parameter/dif:Category, true())}
74},
75element dgValidSubterm {
76element dgValidTerm {string($parameter/dif:Term)},
77element dgValidTermID {
78element ParentListID {concat($voclib:gcmd_science_valids_terms, '/current')},
79element TermID {escape-uri($parameter/dif:Term, true())}
80},
81if (exists($parameter/dif:Variable)) then
82element dgValidSubterm {
83element dgValidTerm {string($parameter/dif:Variable)},
84element dgValidTermID {
85element ParentListID {concat($voclib:gcmd_science_valids_variables, '/current')},
86element TermID {escape-uri($parameter/dif:Variable, true())}
87},
88if (exists($parameter/dif:Detailed_Variable)) then
89element dgValidSubterm {
90element dgValidTerm {string($parameter/dif:Detailed_Variable)},
91element dgValidTermID {
92element ParentListID {$voclib:unknown_vocab_id},
93element TermID {escape-uri($parameter/dif:Detailed_Variable, true())}
94},
95element ListLevel {4}}
96else (),
97element ListLevel {3}
98}
99else (),
100element ListLevel {2}
101},
102element ListLevel {1}
103},
104element ListLevel {0}
105},
106element ParameterName {
107concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)),
108if (exists($parameter/dif:Variable)) then
109concat(' > ', string($parameter/dif:Variable))
110else (),
111if (exists($parameter/dif:Detailed_Variable)) then
112concat(' > ', string($parameter/dif:Detailed_Variable))
113else ()
114},
115element ParameterAbbreviation {
116concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)),
117if (exists($parameter/dif:Variable)) then
118concat(' > ', string($parameter/dif:Variable))
119else (),
120if (exists($parameter/dif:Detailed_Variable)) then
121concat(' > ', string($parameter/dif:Detailed_Variable))
122else ()
123}
124},
125if (exists($DIF/dif:Spatial_Coverage) or exists($DIF/dif:Paleo_Temporal_Coverage) or exists($DIF/dif:Location) or exists($DIF/dif:Temporal_Coverage)) then
126element dgDataCoverage {
127if (exists($DIF/dif:Spatial_Coverage)  or exists($DIF/dif:Location))  then
128element dgSpatialCoverage {
129for $boundingbox in $DIF/dif:Spatial_Coverage[exists(dif:Northernmost_Latitude)
130and exists(dif:Southernmost_Latitude)
131and exists(dif:Easternmost_Longitude)
132and exists(dif:Westernmost_Longitude)]
133return
134element BoundingBox {
135element LimitNorth {data(inputParse:fix-coord($boundingbox/dif:Northernmost_Latitude))},
136element LimitSouth {data(inputParse:fix-coord($boundingbox/dif:Southernmost_Latitude))},
137element LimitWest {data(inputParse:fix-coord($boundingbox/dif:Westernmost_Longitude))},
138element LimitEast {data(inputParse:fix-coord($boundingbox/dif:Easternmost_Longitude))}
139},
140for $location in $DIF/dif:Location
141return
142element dgArea {
143element dgValidTerm {string($location)},
144element dgValidTermID {
145element ParentListID {concat($voclib:gcmd_location_valids, '/current')},
146element TermID {escape-uri($location, true())}
147}
148}
149}
150else (),
151if (exists($DIF/dif:Temporal_Coverage) or exists($DIF/dif:Paleo_Temporal_Coverage) or exists($DIF/dif:Chronostratigraphic_Unit)) then
152element dgTemporalCoverage {
153for $temporalcoverage in $DIF/dif:Temporal_Coverage[exists(dif:Start_Date)]
154return
155element DateRange {
156element DateRangeStart {string($temporalcoverage/dif:Start_Date)},
157element DateRangeEnd {string($temporalcoverage/dif:Stop_Date)}
158},
159for $paleotemporalcoverage in $DIF/dif:Paleo_Temporal_Coverage[exists(dif:Paleo_Start_Date)]
160return
161element DateRange {
162element DateRangeStart {string($paleotemporalcoverage/dif:Paleo_Start_Date)},
163element DateRangeEnd {string($paleotemporalcoverage/dif:Paleo_Stop_Date)}
164},
165for $chronostratigraphic in $DIF/dif:Chronostratigraphic_Unit
166return
167element dgChronostratigraphicTerm {
168element dgValidTerm {string($chronostratigraphic)},
169element dgValidTermID {
170element ParentListID {concat($voclib:gcmd_chronostratigraphic_valids, '/current')},
171element TermID {escape-uri($chronostratigraphic, true())}
172}
173}
174}
175else ()
176}
177else ()
178},
179element dgDataRoles {
180if (exists($DIF/dif:Data_Set_Citation/dif:Dataset_Creator)) then
181element dgDataCreator {
182element dgMetadataID {
183element schemeIdentifier {'NDG-B0'},
184element repositoryIdentifier {$input_repository},
185if ($output_local_id != 'Output_LocalID') then
186element localIdentifier {concat('generated_creator-', $output_local_id)}
187else
188element localIdentifier {concat('generated_creator-', escape-uri(string($DIF/dif:Entry_ID), true()))}
189},
190element roleName {'Data Creator'},
191element abbreviation {'Creator'},
192for $creatorID in $DIF/dif:Data_Set_Citation/dif:Dataset_Creator
193return
194element dgRoleHolder {
195element dgOrganisationID {
196element schemeIdentifier {'NDG-B0'},
197element repositoryIdentifier {$input_repository},
198if ($output_local_id != 'Output_LocalID') then
199element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())}
200else
201element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())}
202},
203element startDate {current-date()}
204}
205}
206else if (exists($DIF/dif:Originating_Center)) then
207element dgDataCreator {
208element dgMetadataID {
209element schemeIdentifier {'NDG-B0'},
210element repositoryIdentifier {$input_repository},
211if ($output_local_id != 'Output_LocalID') then
212element localIdentifier  {escape-uri(concat('generated_creator-', $output_local_id), true())}
213else
214element localIdentifier  {escape-uri(concat('generated_creator-', data($DIF/dif:Entry_ID)), true())}
215},
216element roleName {'Data Creator'},
217element abbreviation {'Creator'},
218for $creatorID in $DIF/dif:Originating_Center
219return
220element dgRoleHolder {
221element dgOrganisationID {
222element schemeIdentifier {'NDG-B0'},
223element repositoryIdentifier {$input_repository},
224if ($output_local_id != 'Output_LocalID') then
225element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', $output_local_id), true())}
226else
227element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creatorID), '-', data($DIF/dif:Entry_ID)), true())}
228},
229element startDate {current-date()}
230}
231}
232else (),
233element dgDataCurator {
234element dgMetadataID {
235element schemeIdentifier {'NDG-B0'},
236element repositoryIdentifier {$input_repository},
237if ($output_local_id != 'Output_LocalID') then
238element localIdentifier  {escape-uri(concat('generated_curator-', $output_local_id), true())}
239else
240element localIdentifier  {escape-uri(concat('generated_curator-', data($DIF/dif:Entry_ID)), true())}
241},
242element roleName {'Data Curator'},
243element abbreviation {'Curator'},
244element dgRoleHolder {
245element dgOrganisationID {
246element schemeIdentifier {'NDG-B0'},
247element repositoryIdentifier {$input_repository},
248element localIdentifier {$input_repository_local}
249},
250element startDate {current-date()}
251}
252}
253}
254},
255element dgStructuredKeyword {
256element dgValidTerm {'d2b converted record'},
257element dgValidTermID {
258element ParentListID {$voclib:unknown_vocab_id},
259element TermID {'d2b'}
260}
261},
262for $structuredKeywords in $DIF/dif:Keyword
263return
264element dgStructuredKeyword {
265element dgValidTerm {string($structuredKeywords)},
266element dgValidTermID {
267if ($structuredKeywords='MDIP' or $structuredKeywords='NERC' or $structuredKeywords='NERC_DDC') then
268element ParentListID {concat($voclib:ndg_data_provider_vocab, '/current')}
269else
270element ParentListID {$voclib:unknown_vocab_id}
271,
272element TermID {escape-uri($structuredKeywords, true())}
273}
274},
275for $structuredKeywords in $DIF/dif:ISO_Topic_Category
276return
277element dgStructuredKeyword {
278element dgValidTerm {string($structuredKeywords)},
279element dgValidTermID {
280element ParentListID {concat($voclib:iso_topic_list, '/current')},
281element TermID {escape-uri($structuredKeywords, true())}
282}
283},
284if (exists($DIF/dif:DIF_Creation_Date) or exists($DIF/dif:Last_DIF_Revision_Date)) then
285element dgMetadataProvenance {
286if (exists($DIF/dif:DIF_Creation_Date)) then
287element RecordCreation {
288element CreatedDate {
289if (string($DIF/dif:DIF_Creation_Date) castable as xs:date) then
290string($DIF/dif:DIF_Creation_Date) cast as xs:date
291else (current-date())
292},
293element CreatedBy {$input_repository}
294}
295else
296element RecordCreation {
297element CreatedDate {current-date()},
298element CreatedBy {'MOLES Import'}
299},
300if (exists($DIF/dif:Last_DIF_Revision_Date)) then
301element RecordUpdate {
302element UpdateDate {
303if (string($DIF/dif:Last_DIF_Revision_Date) castable as xs:dateTime) then
304string($DIF/dif:Last_DIF_Revision_Date) cast as xs:dateTime
305else (current-dateTime())
306},
307element UpdatedBy {$input_repository}
308}
309else ()
310}
311else ()
312} (: </dgMetadataRecord>:),
313for $creator in distinct-values($DIF/(dif:Data_Set_Citation/dif:Dataset_Creator | dif:Originating_Center))
314return
315element dgOrganisation {
316element dgMetadataID {
317element schemeIdentifier {'NDG-B0'},
318element repositoryIdentifier {$input_repository},
319if ($output_local_id != 'Output_LocalID') then
320element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creator), '-', $output_local_id), true())}
321else
322element localIdentifier  {escape-uri(concat('generated_orgcit-', string($creator), '-', data($DIF/dif:Entry_ID)), true())}
323},
324element name {string($creator)},
325element abbreviation {string($creator)},
326element contactDetails {''}
327}
328} (:    </dgMetadata> :)
Note: See TracBrowser for help on using the repository browser.