source: exist/trunk/xquery/stubB_observationStation.xq @ 3841

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/stubB_observationStation.xq@4326
Revision 3841, 8.7 KB checked in by cbyrom, 12 years ago (diff)

Various updates to the xquery files - to remove usage of invalid specs
and dependency on obsolete function calls. Also add the inputParse_xquery_lib.xquery
file - referenced from the xquery files but not currently included in codebase.
NB, changes made to allow use of Saxon java library to do xqueries - to
remove the need for the discovery service eXist DB.

  • NB, also changes tested by comparing saxon transforms to eXist ones; these

were found to be identical.

Line 
1(: This query for TargetCollection, RepositoryID and LocalID, will return the stubB for an observation station :)
2declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';
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 := 'TargetCollection';
12declare variable $repositoryIdentifier as xs:string := 'RepositoryID';
13declare variable $localIdentifier as xs:string := 'LocalID';
14declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
15(: Returns a 'stubB' style activity record to expand an activity record :)
16(: Security not implemented here yet :)
17{
18let $SRAct := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
19moles:dgMetadataID/moles:localIdentifier=$locid
20and moles:dgMetadataID/moles:repositoryIdentifier=$repid ]
21return
22element  {$out-element-name} {
23($SRAct/moles:dgMetadataID),
24($SRAct/moles:dgMetadataDescription),
25($SRAct/moles:name),
26($SRAct/moles:abbreviation),
27($SRAct/moles:logos)
28} (: </activity> :)
29} ;
30
31declare function f:return-stub-dataentity($out-element-name as xs:string, $DE as element()) as element()
32(: Returns a 'stubB' style observation station record to expand an data entity record :)
33(: Security not implemented yet :)
34{
35let $SRDE := $DE
36return 
37element {$out-element-name} {
38($SRDE/moles:dgMetadataID),
39($SRDE/moles:dgMetadataDescription),
40($SRDE/moles:name),
41($SRDE/moles:abbreviation)
42} (: </dgDataEntity> :)       
43} ;
44
45declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
46(: Returns a 'stubB' style dpt record to expand a dpt record :)
47(: Security not implemented yet :)
48{
49let $SRDPT := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
50moles:dgMetadataID/moles:localIdentifier=$locid
51and
52moles:dgMetadataID/moles:repositoryIdentifier=$repid
53]
54return 
55element {$out-element-name} {
56$SRDPT/moles:dgMetadataID,
57$SRDPT/moles:dgMetadataDescription,
58$SRDPT/moles:name,
59$SRDPT/moles:abbreviation,
60$SRDPT/moles:logos
61} (: </dataproductiontool> :)
62} ;
63
64declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
65(: Returns a 'stubB' style observation station record to expand an observation station record :)
66(: Security not implemented here yet;  :)
67{
68let $SRObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
69moles:dgMetadataID/moles:localIdentifier=$locid
70and
71moles:dgMetadataID/moles:repositoryIdentifier=$repid
72]
73return
74element {$out-element-name} {
75($SRObsStn/moles:dgMetadataID),
76($SRObsStn/moles:dgMetadataDescription),
77($SRObsStn/moles:name),
78($SRObsStn/moles:abbreviation),
79($SRObsStn/moles:logos)
80}
81} ;
82
83declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
84(: Returns a 'stubB' style observation station record to expand a person record :)
85(: Security not implemented yet :)
86{
87let $person := collection($targetCollection)/moles:dgMetadata/moles:dgPerson[
88moles:dgMetadataID/moles:localIdentifier=$locid
89and
90moles:dgMetadataID/moles:repositoryIdentifier=$repid
91]
92return
93element  {$out-element-name}
94{
95($person/moles:name),
96($person/moles:contactDetails),
97($person/moles:dgMetadataID)
98}
99} ;
100
101declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element()
102(: Returns a 'stubB' style observation station record to expand an organisation record :)
103(: Security not implemented yet :)
104{
105let $org := collection($targetCollection)/moles:dgMetadata/moles:dgOrganisation[
106moles:dgMetadataID/moles:localIdentifier=$locid
107and
108moles:dgMetadataID/moles:repositoryIdentifier=$repid
109]
110return
111element  {$out-element-name} {
112$org/moles:dgMetadataID,
113$org/moles:name,
114$org/moles:abbreviation,
115$org/moles:contactDetails,
116$org/moles:logos
117}
118} ;
119
120let $ObsStn := collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
121moles:dgObservationStation!=''
122and moles:dgMetadataID[
123moles:repositoryIdentifier=$repositoryIdentifier
124and moles:localIdentifier=$localIdentifier]]
125return
126utillib:strip-namespace(
127element dgMetadataRecord {
128element dgMetadataID {
129element schemeIdentifier {'NDG-B1'},
130$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
131$ObsStn/moles:dgMetadataID/moles:localIdentifier
132} (: End </dgMetadataID> :),
133$ObsStn/moles:dgMetadataDescription,
134$ObsStn/moles:name,
135$ObsStn/moles:abbreviation,
136element dgObservationStation {
137$ObsStn/moles:dgObservationStation/moles:contactDetails,
138if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
139element dgStationaryPlatform {
140$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
141if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
142element dgMooring {
143$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
144$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
145for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
146return
147f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
148if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
149for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
150return 
151f:return-stub-obsstn('dgStationGrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
152else ()
153} (: End </dgMooring> :) 
154else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
155element dgStationGroup {
156element dgGroupedStations {
157if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
158for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
159return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
160else ()
161} (: End </dgGroupedStations> :)
162} (: End </dgStationGroup> :)
163else $ObsStn/moles:dgObservationStation/moles:dgLandStation
164} (: End </dgStationaryPlatform>  :) 
165else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform ,
166element DeploymentSummary {
167element activityList {
168for $DepActRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:ActivityID/moles:repositoryIdentifier)
169for $DepActLocal in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:ActivityID/moles:localIdentifier)
170let $DepAct :=  f:return-stub-activity('activity', data($DepActRepository), data($DepActLocal))
171return $DepAct
172},
173element dptList {
174for $DepDPTRepository in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:DataProductionToolID/moles:repositoryIdentifier)
175for $DepDPTLocal in distinct-values($ObsStn/moles:dgObservationStation/moles:ObsStationDeployment/moles:DataProductionToolID/moles:localIdentifier)
176let $DepDPT :=  f:return-stub-dpt('dataproductiontool', data($DepDPTRepository), data($DepDPTLocal))
177return $DepDPT
178},
179element dataEntityList {
180for $DE in
181collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataEntity/moles:RelatedDeployment
182/moles:ObservationStationID
183[moles:localIdentifier=$ObsStn/moles:dgMetadataID/moles:localIdentifier
184and moles:repositoryIdentifier=$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier]]
185order by $DE/moles:dgMetadataID
186return f:return-stub-dataentity('dataentity', $DE)
187}
188, element rawDeployments {for $rawDeployments in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment return $rawDeployments}
189} (: </DeploymentSummary> :)
190} (: </dgObservationStation> :),
191for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
192if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
193if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
194} (: End </dgMetadataRecord> :)
195) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.