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

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

v0.9 of namespaced xqueries

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