source: TI07-MOLES/trunk/StubB/XQuery/NDG-ObsStnStubB.xquery @ 2511

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XQuery/NDG-ObsStnStubB.xquery@2511
Revision 2511, 10.5 KB checked in by ko23, 12 years ago (diff)

Update voclib to include Roy's new IDs. Add version variable to libraries. Change ObsStn? xq to point at 375 deployment example

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';
2import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery';
3import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
4(:
5Will return when scope problem sussed... ;(
6import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
7:)
8declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
9declare namespace moles='http://ndg.nerc.ac.uk/moles';
10
11declare variable $targetCollection as xs:string {'/db/ndg_B_metadata'};
12declare variable $repositoryIdentifier as xs:string {'badc.nerc.ac.uk'};
13declare variable $localIdentifier as xs:string {'obs_1162914661529326'};
14(: replacable parameters
15declare variable $targetCollection as xs:string {'TargetCollection'};
16declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
17declare variable $localIdentifier as xs:string {'LocalID'};
18:)
19declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
20(: Returns a 'stubB' style activity record to expand an activity record :)
21(: Security not implemented here yet :)
22{
23let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
24moles:dgMetadataID/moles:localIdentifier=$locid
25and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
26return
27element  {$out-element-name} {
28($SRAct/moles:dgMetadataID),
29($SRAct/moles:dgMetadataDescription),
30($SRAct/moles:name),
31($SRAct/moles:abbreviation),
32($SRAct/moles:logos),
33element dgActivity {
34if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCollection)) then
35($SRAct/*/moles:dgActivityDataCollection)
36else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataProject)) then
37($SRAct/*/moles:dgActivityDataProject)
38else if (exists($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)) then
39($SRAct/moles:dgActivity/moles:dgActivityDataCampaign)
40else
41($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),
42($SRAct/moles:dgActivity/moles:dgActivityCoverage),
43($SRAct/moles:dgActivity/moles:dgActivityDuration)
44} (: </dgActivity> :)
45} (: </activity> :)
46} ;
47
48declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
49(: Returns a 'stubB' style observation station record to expand an data entity record :)
50(: Security not implemented yet :)
51{
52let $SRDE := $DE
53return 
54element {$out-element-name} {
55($SRDE/moles:dgMetadataID),
56($SRDE/moles:dgMetadataDescription),
57($SRDE/moles:name),
58($SRDE/moles:abbreviation),
59element dgDataEntity {
60($SRDE/moles:dgDataEntity/moles:dgDataSetType),
61($SRDE/moles:dgDataEntity/moles:dgDataGranule),
62($SRDE/moles:dgDataEntity/moles:dgDataSummary)
63} (: </dgDataEntity> :)       
64}
65} ;
66
67declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
68(: Returns a 'stubB' style dpt record to expand a dpt record :)
69(: Security not implemented yet :)
70{
71let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
72moles:dgMetadataID/moles:localIdentifier=$locid
73and
74moles:dgMetadataID/moles:repositoryIdentifier=$repid
75]
76return 
77element {$out-element-name} {
78$SRDPT/moles:dgMetadataID,
79$SRDPT/moles:dgMetadataDescription,
80$SRDPT/moles:name,
81$SRDPT/moles:abbreviation,
82$SRDPT/moles:logos,
83element dgDataProductionTool {
84$SRDPT/moles:dgDataProductionTool/moles:contactDetails,
85if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then
86$SRDPT/moles:dgDataProductionTool/moles:dgModel
87else (),
88if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then
89$SRDPT/moles:dgDataProductionTool/moles:dgInstrument
90else ()
91} (: </dgDataProductionTool> :)
92} (: </dataproductiontool> :)
93} ;
94
95declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
96(: Returns a 'stubB' style observation station record to expand an observation station record :)
97(: Security not implemented here yet;  :)
98{
99let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
100moles:dgMetadataID/moles:localIdentifier=$locid
101and
102moles:dgMetadataID/moles:repositoryIdentifier=$repid
103]
104return
105element {$out-element-name} {
106($SRObsStn/moles:dgMetadataID),
107($SRObsStn/moles:dgMetadataDescription),
108($SRObsStn/moles:name),
109($SRObsStn/moles:abbreviation),
110($SRObsStn/moles:logos),
111element dgObservationStation {
112($SRObsStn/moles:dgObservationStation/moles:contactDetails),
113if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
114element dgStationaryPlatform {
115$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
116if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgLandStation)) then element dgLandStation {''}
117else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {''}
118else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgStationGroup)) then element dgStationGroup {''}
119else ()
120}
121else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then
122$SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform
123else ()
124} (: </dgObservationStation> :)
125}
126} ;
127
128declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
129(: Returns a 'stubB' style observation station record to expand a person record :)
130(: Security not implemented yet :)
131{
132let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
133moles:dgMetadataID/moles:localIdentifier=$locid
134and
135moles:dgMetadataID/moles:repositoryIdentifier=$repid
136]
137return
138element  {$out-element-name}
139{
140($person/moles:name),
141($person/moles:contactDetails),
142($person/moles:dgMetadataID)
143}
144} ;
145
146declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
147(: Returns a 'stubB' style observation station record to expand an organisation record :)
148(: Security not implemented yet :)
149{
150let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
151moles:dgMetadataID/moles:localIdentifier=$locid
152and
153moles:dgMetadataID/moles:repositoryIdentifier=$repid
154]
155return
156element  {$out-element-name} {
157$org/moles:dgMetadataID,
158$org/moles:name,
159$org/moles:abbreviation,
160$org/moles:contactDetails,
161$org/moles:logos
162}
163} ;
164
165let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
166moles:dgObservationStation!=''
167and moles:dgMetadataID[
168moles:schemeIdentifier='NDG-B0'
169and moles:repositoryIdentifier=$repositoryIdentifier
170and moles:localIdentifier=$localIdentifier]]
171return
172utillib:strip-namespace(
173element dgMetadataRecord {
174element dgMetadataID {
175element schemeIdentifier {'NDG-B1'},
176$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
177$ObsStn/moles:dgMetadataID/moles:localIdentifier
178} (: End </dgMetadataID> :),
179$ObsStn/moles:dgMetadataDescription,
180$ObsStn/moles:name,
181$ObsStn/moles:abbreviation,
182element dgObservationStation {
183$ObsStn/moles:dgObservationStation/moles:contactDetails,
184if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
185element dgStationaryPlatform {
186$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
187if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
188element dgMooring {
189$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
190$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
191for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
192return
193f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
194if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
195for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
196return 
197f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
198else ()
199} (: End </dgMooring> :) 
200else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
201element dgStationGroup {
202element dgGroupedStations {
203if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
204for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
205return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
206else ()
207} (: End </dgGroupedStations> :)
208} (: End </dgStationGroup> :)
209else $ObsStn/moles:dgObservationStation/moles:dgLandStation
210} (: End </dgStationaryPlatform>  :) 
211else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
212for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment
213return
214element ObsStationDeployment {
215$RelDep/moles:DateStart,
216$RelDep/moles:DateEnd,
217$RelDep/moles:dgMetadataID,
218f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
219f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
220for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
221and moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier]
222return
223f:return-stub-dataentity('dataentity', $DE),
224$RelDep/moles:Coverage
225} (: </RelatedDeployment> :)
226} (: </dgObservationStation> :),
227for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
228if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
229if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
230} (: End </dgMetadataRecord> :)
231) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.