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

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

Refactoring intermediate

  • 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';
4import module namespace stubblib='http://ndg.nerc.ac.uk/xquery/lib/stubb' at 'xmldb:exist:///db/xqueryLib/StubB/stubb_xquery_lib.xquery';
5declare namespace moles='http://ndg.nerc.ac.uk/moles';
6
7declare variable $targetCollection as xs:string {'TargetCollection'};
8declare variable $repositoryIdentifier as xs:string {'RepositoryID'};
9declare variable $localIdentifier as xs:string {'LocalID'};
10
11for $ObsStn in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
12moles:dgDataProductionTool!=''
13and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
14and moles:dgMetadataID/moles:repositoryIdentifier=$repositoryIdentifier
15and moles:dgMetadataID/moles:localIdentifier=$localIdentifier]
16return
17utillib:strip-namespace(element dgMetadataRecord {
18        element dgMetadataRecord {
19                element dgMetadataID {
20                        element schemeIdentifier {'NDG-B1',
21                        $ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,
22                        $ObsStn/moles:dgMetadataID/moles:localIdentifier
23                } (: End </dgMetadataID> :),
24                $ObsStn/moles:dgMetadataDescription,
25                $ObsStn/moles:name,
26                $ObsStn/moles:abbreviation,
27                element dgObservationStation {
28                        $ObsStn/moles:dgObservationStation/moles:contactDetails,
29                        if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then
30                                element dgStationaryPlatform {
31                                $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,
32                                if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then   
33                                        element dgMooring {
34                                                $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,
35                                                $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,
36                                                for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise
37                                                return
38                                                        stubblib:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),
39                                                        if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then   
40                                                                for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping
41                                                                return 
42                                                                        stubblib:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier))
43                                                        else ()
44                                        } (: End </dgMooring> :) 
45                                else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then   
46                                        element dgStationGroup {
47                                                element dgGroupedStations {
48                                                        if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then
49                                                                for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations
50                                                                return stubblib:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier))
51                                                        else ()
52                                                } (: End </dgGroupedStations> :)
53                                        } (: End </dgStationGroup> :)
54                                else $ObsStn/moles:dgObservationStation/moles:dgLandStation
55                                } (: End </dgStationaryPlatform>  :) 
56                                else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform
57                        } ,
58                        for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment
59                        return
60                                element ObsStationDeployment {
61                                $RelDep/moles:DateStart,
62                                $RelDep/moles:DateEnd,
63                                $RelDep/moles:dgMetadataID,
64                                stubblib:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
65                                stubblib:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),
66                                for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord
67                                        where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
68                                                and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier
69                                return
70                                        stubblib:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),
71                                $RelDep/moles:Coverage
72                        } (: </RelatedDeployment> :)
73                } (: </dgObservationStation> :),
74        for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,
75        if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),
76        if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()
77        } (: End </dgMetadataRecord> :)
78) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.