source: exist/trunk/xquery/atom2DIF.xq @ 4421

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/atom2DIF.xq@4421
Revision 4421, 6.4 KB checked in by cbyrom, 11 years ago (diff)

Add the atom2DIF xquery transform.

Line 
1declare default element namespace 'http://www.w3.org/2005/Atom';
2declare namespace dif = 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
3declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
4declare namespace moles="http://ndg.nerc.ac.uk/schema/moles2alpha";
5declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
6declare namespace georss = "http://www.georss.org/georss";
7declare namespace gml = "http://www.opengis.net/gml";
8declare namespace fn = "http://www.w3.org/2005/02/xpath-functions";
9
10import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
11import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
12
13(: Keep this in official lib version
14declare variable $targetCollection as xs:string := 'TargetCollection/Published/data_entities/RepositoryID';
15declare variable $deploymentsCollection as xs:string := 'TargetCollection/Published/deployments/RepositoryID';
16declare variable $repositoryIdentifier as xs:string := 'RepositoryID';
17declare variable $localIdentifier as xs:string := 'LocalID';
18declare variable $dptTerm as xs:string := 'DPTTerm';
19declare variable $obsTerm as xs:string :=  'OBSTerm';
20declare variable $activityTerm as xs:string :=  'ACTIVITYTerm';
21declare variable $uriTerm as xs:string :=  'URITerm';
22declare variable $granuleTerm as xs:string :=  'GranuleTerm';
23:)
24
25declare variable $targetCollection as xs:string := '/db/atoms';
26declare variable $deploymentsCollection as xs:string := '/db/atoms';
27declare variable $repositoryIdentifier as xs:string := 'badc.nerc.ac.uk';
28declare variable $localIdentifier as xs:string := 'dataent_WLSTA';
29declare variable $dptTerm as xs:string := 'DPT - NOT YET SET UP/None/DPT';
30declare variable $obsTerm as xs:string :=  'OBS - NOT YET SET UP/None/OBS';
31declare variable $activityTerm as xs:string :=  'ACTIVITY - NOT YET SET UP/None/OBS';
32declare variable $granuleTerm as xs:string :=  'GRAN - NOT YET SET UP/None/GRANULE';
33declare variable $uriTerm as xs:string :=  'URI';
34
35for $DE in collection($targetCollection)/entry[matches(id, concat('__ATOM__',$localIdentifier,'$'))]
36return
37element DIF {
38        attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},
39        element Entry_ID {concat(string($DE/moles:entity/moles:molesISO/moles:providerID),':DIF:', tokenize(string($DE/id), '__ATOM__')[2])},
40        element Entry_Title {string($DE/title)},
41        element Data_Set_Citation {
42            element Dataset_Creator {string($DE/author/name)},
43            element Dataset_Title {string($DE/title)}
44        },
45        element Personnel {
46            element Role {''},
47            element Last_Name {''}
48        },
49        element Discipline { element Discipline_Name {''} },
50        element Parameters { element Category {''}, element Topic {''}, element Term {''} },
51
52           for $deploymentID in ($DE/link[@rel = 'ActivityDeployment'])
53               return
54               for $atom in ($deploymentsCollection/entry[link[@href = $deploymentID] and category[@label = 'Deployment']])
55               return
56                   for $dpt in ($atom[link[@rel = $dptTerm]])
57                       return
58                    element Sensor_Name {
59                           element Long_Name {data($dpt[title])}
60                    },
61           for $deploymentID in ($DE/link[@rel = 'ActivityDeployment'])
62               return
63               for $atom in ($deploymentsCollection/entry[link[@href = $deploymentID] and category[@label = 'Deployment']])
64               return
65                   for $obs in ($atom[link[@rel =$obsTerm]])
66                       return
67                    element Source_Name {
68                           element Long_Name {data($obs[title])}
69                    },
70           for $deploymentID in ($DE/link[@rel = 'ActivityDeployment'])
71               return
72               for $atom in ($deploymentsCollection/entry[link[@href = $deploymentID] and category[@label = 'Deployment']])
73               return
74                   for $activity in ($atom[link[@rel =$activityTerm]])
75                       return
76                    element Project {
77                           element Long_Name {data($activity[title])}
78                    },
79
80           for $TemporalRange in $DE/moles:temporalRange
81        return
82            element Temporal_Coverage
83                        {
84                        element Start_Date {tokenize(string($DE/moles:temporalRange), '/')[0]},
85                        element Stop_Date {tokenize(string($DE/moles:temporalRange), '/')[1]}
86                        },
87           
88        for $BoundingBox in $DE//georss:where/gml:Envelope
89        return
90            element Spatial_Coverage {
91                    element Southernmost_Latitude {data($BoundingBox/gml:lowerCorner)},
92                    element Northernmost_Latitude {tokenize(string($BoundingBox/gml:upperCorner), '')[1]},
93                    element Westernmost_Longitude {tokenize(string($BoundingBox/gml:lowerCorner), '')[0]},
94                    element Easternmost_Longitude {tokenize(string($BoundingBox/gml:upperCorner), '')[0]}
95                },
96         
97        element Data_Resolution {''},
98        element Quality {''},
99        element Use_Constraints {''},
100        element Data_Set_Language {''},
101        element Distribution {''},
102        element Multimedia_Sample {''},
103        element Reference {''},
104        element Summary {string($DE/summary)},
105           for $link in ($DE/link[@rel = $granuleTerm])
106               return
107                    element Related_URL {
108                            element URL {data($link[@href])},
109                               element Description {data($link[@title])}
110                               },
111
112           for $link in ($DE/link[@rel = $uriTerm])
113               return
114                    element Related_URL {
115                            element URL {data($link[@href])},
116                               element Description {data($link[@title])}
117                               },
118        element Parent_DIF {''},
119        element IDN_Node { element Short_Name {''} },
120        element Originating_Metadata_Node {''},
121        element Metadata_Name {'[CEOS IDN DIF]'},
122        element Metadata_Version {'9.4'},
123        if  (exists($DE/moles:entity/moles:molesISO/moles:created)) then
124                element DIF_Creation_Date {data($DE/moles:entity/moles:molesISO/moles:created)}
125        else (),
126        if  (exists($DE/updated)) then
127                element DIF_Revision_History {data($DE/updated)} (: missing updator + summary... :)
128        else ()
129        }
Note: See TracBrowser for help on using the repository browser.