source: TI07-MOLES/trunk/StubB/XQuery/NDG-DPTStubBnew.xquery @ 2236

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

Refactoring - working versions. Still slow though.

Line 
1declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataproductiontool';
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 $DPT 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        $DPT/dgMetadataID,
19                element dgMetadataID {
20                        element schemeIdentifier {'NDG-B1'},
21                        $DPT/moles:dgMetadataID/moles:repositoryIdentifier,
22                        $DPT/moles:dgMetadataID/moles:localIdentifier
23                } (: End </dgMetadataID> :),
24        $DPT/moles:dgMetadataDescription,
25        $DPT/moles:name,
26        $DPT/moles:abbreviation,
27        element dgDataProductionTool {
28                $DPT/moles:contactDetails,
29                if (exists($DPT/moles:dgModel)) then $DPT/moles:dgModel
30                else $DPT/moles:dgInstrument
31        ,
32        if (exists($DPT/moles:dgDPTRoles)) then
33                element dgDPTRoles {'Roles are available, and will be added soon'}
34         else(),
35        for $RelDep in $DPT/moles:dgDataProductionTool/moles:DPTDeployment
36        return
37                element DPTDeployment {
38                        $RelDep/moles:DateStart,
39                        $RelDep/moles:DateEnd,
40                        $RelDep/moles:dgMetadataID,
41                        stubblib:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),
42                        stubblib:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),
43                        for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord
44                                where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier
45                                        and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier
46                        return
47                                stubblib:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),
48                        $RelDep/moles:Coverage
49                } (: </DPTDeployment> :)
50        } (: </dgDataProductionTool> :),
51        for $strkwrd in $DPT/moles:dgStructuredKeyword return $strkwrd,
52        if (exists($DPT/moles:dgMetadataProvenance)) then $DPT/moles:dgMetadataProvenance else (),
53        if (exists($DPT/moles:dgMetadataSecurity)) then $DPT/moles:dgMetadataSecurity else ()
54} (:End </dgMetadataRecord> :)
55) (: End namespace strip :)
Note: See TracBrowser for help on using the repository browser.