source: TI07-MOLES/trunk/PythonCode/wsgi/ndg_xqueries.py @ 2008

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/PythonCode/wsgi/ndg_xqueries.py@2008
Revision 2008, 80.3 KB checked in by ko23, 14 years ago (diff)

Updated XQueries (DIF/DC) B->D part 1

Line 
1# This version using xqueries from rev 1914 of
2# TI07-MOLES/trunk/JavaCode/returnmolesxmldb/ndg/services/returnmoles/Main.java
3# Update DIF/DC queries
4listingQuery='''
5declare default element namespace 'http://ndg.nerc.ac.uk/moles';for $DE
6in
7collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[exists(dgDataEntity)] return
8<dgMetadataRecord>{$DE/dgMetadataID/repositoryIdentifier}
9{$DE/dgMetadataID/localIdentifier}<fileName>{util:document-name($DE)}</fileName></dgMetadataRecord>
10'''
11
12ObjectTypeQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles';for $Obj in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID']  return <objectType>{if (exists($Obj/dgDataEntity)) then 4 else (if (exists($Obj/dgObservationStation)) then 3 else (if (exists($Obj/dgDataProductionTool)) then 2 else (if (exists($Obj/dgActivity)) then 1 else (0))))}</objectType>'''
13
14StubBDEQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataentity';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid])return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[exists(moles:dgDataEntity)and moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier='RepositoryID' and moles:localIdentifier='LocalID']] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1'},$DE/moles:dgMetadataID/moles:repositoryIdentifier,$DE/moles:dgMetadataID/moles:localIdentifier},$DE/moles:dgMetadataDescription,$DE/moles:name,$DE/moles:abbreviation,element dgDataEntity {$DE/moles:dgDataEntity/moles:dgDataSetType,$DE/moles:dgDataEntity/moles:dgDataObjectType,$DE/moles:dgDataEntity/moles:dgDataGranule,$DE/moles:dgDataEntity/moles:dgDataSummary,element dgDataRoles {if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID)) then element dgDataCreator {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:contactDetails,for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder order by $DataCreatorRole/moles:startDate empty least, $DataCreatorRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataCreatorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCreatorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCreatorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCreatorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCreatorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCreatorRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataCreatorRole/moles:startDate,$DataCreatorRole/moles:endDate,$DataCreatorRole/moles:localName}} else (),if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID)) then element dgDataCurator {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:contactDetails,for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder order by $DataCuratorRole/moles:startDate empty least, $DataCuratorRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataCuratorRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataCuratorRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataCuratorRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataCuratorRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataCuratorRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataCuratorRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataCuratorRole/moles:startDate,$DataCuratorRole/moles:endDate,$DataCuratorRole/moles:localName}} else (),if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID)) then element dgDataOtherRoles {$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgMetadataID,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:roleName,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:abbreviation,$DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:contactDetails,for $DataOtherRolesRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataOtherRoles/moles:dgRoleHolder order by $DataOtherRolesRole/moles:startDate empty least, $DataOtherRolesRole/moles:endDate empty least return element dgRoleHolder {if (exists($DataOtherRolesRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($DataOtherRolesRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($DataOtherRolesRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($DataOtherRolesRole/moles:dgPersonID)) then f:return-stub-person('person', string($DataOtherRolesRole/moles:dgPersonID/moles:repositoryIdentifier), string($DataOtherRolesRole/moles:dgPersonID/moles:localIdentifier)) else (),$DataOtherRolesRole/moles:startDate,$DataOtherRolesRole/moles:endDate,$DataOtherRolesRole/moles:localName}} else ()},for $RelDep in $DE/moles:dgDataEntity/moles:RelatedDeployment return element RelatedDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),$RelDep/moles:Coverage},for $RelatedDataEntity in $DE/moles:dgDataEntity/moles:dgRelatedDataEntity return element relateddataentity {element relation {$RelatedDataEntity/moles:RelationID/moles:dgValidTerm,$RelatedDataEntity/moles:RelationID/moles:dgValidTermID},f:return-stub-dataentity('dataentity', data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:repositoryIdentifier), data($RelatedDataEntity/(moles:RelatedDataEntityID | moles:RelatedDataGranuleID)/moles:localIdentifier))}},for $strkwrd in $DE/moles:dgStructuredKeyword return $strkwrd,if (exists($DE/moles:dgMetadataProvenance)) then $DE/moles:dgMetadataProvenance else (),if (exists($DE/moles:dgMetadataSecurity)) then $DE/moles:dgMetadataSecurity else ()})'''
15
16StubBActQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/activity'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';  declare function f:strip-namespace($e as element()) as element() {element {QName('', local-name($e))} {let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}} ;  declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID), ($SRAct/moles:dgMetadataDescription), ($SRAct/moles:name), ($SRAct/moles:abbreviation), element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation), ($SRAct/moles:dgActivity/moles:dgActivityCoverage), ($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID), ($SRDE/moles:dgMetadataDescription), ($SRDE/moles:name), ($SRDE/moles:abbreviation), element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType), ($SRDE/moles:dgDataEntity/moles:dgDataGranule), ($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID, $SRDPT/moles:dgMetadataDescription, $SRDPT/moles:name, $SRDPT/moles:abbreviation, $SRDPT/moles:logos, element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails, if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (), if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})}; declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID), ($SRObsStn/moles:dgMetadataDescription), ($SRObsStn/moles:name), ($SRObsStn/moles:abbreviation), element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails), if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position, if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($person/moles:name), ($person/moles:contactDetails), ($person/moles:dgMetadataID)})}; declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element() {let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'}, element repositoryIdentifier {$repid}, element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID, $org/moles:name, $org/moles:abbreviation, $org/moles:contactDetails, $org/moles:logos})};for $Act in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgActivity!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1'}, (element repositoryIdentifier {data($Act/moles:dgMetadataID/moles:repositoryIdentifier)}), element localIdentifier {data($Act/moles:dgMetadataID/moles:localIdentifier)}}, $Act/moles:dgMetadataDescription, $Act/moles:name, $Act/moles:abbreviation, element dgActivity {for $RelatedActivities in $Act/dgActivity/moles:relatedActivity return element relatedActivity {$RelatedActivities/moles:activityRelation, f:return-stub-activity('activity', data($RelatedActivities/moles:relatedActivityID/moles:repositoryIdentifier), data($RelatedActivities/moles:relatedActivityID/moles:localIdentifier))},if (exists($Act/moles:dgActivity/moles:dgActivityDataCollection)) then ($Act/moles:dgActivity/moles:dgActivityDataCollection) else if (exists($Act/moles:dgActivity/moles:dgActivityDataProject)) then ($Act/moles:dgActivity/moles:dgActivityDataProject) else if (exists($Act/moles:dgActivity/moles:dgActivityDataInvestigation)) then ($Act/moles:dgActivity/moles:dgActivityDataInvestigation) else if (exists($Act/moles:dgActivity/moles:dgActivityDataCampaign)) then ($Act/moles:dgActivity/moles:dgActivityDataCampaign) else (), element dgActivityRole {element dgInvestigator {element dgPrincipalInvestigator {($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:contactDetails), for $PIRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgPrincipalInvestigator/moles:dgRoleHolder order by $PIRole/moles:startDate empty least, $PIRole/moles:endDate empty least return element dgRoleHolder {if (exists($PIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PIRole/moles:dgPersonID)) then f:return-stub-person('person', string($PIRole/moles:dgPersonID/moles:repositoryIdentifier), string($PIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PIRole/moles:startDate), if (exists($PIRole/moles:endDate)) then ($PIRole/moles:endDate) else (), if (exists($PIRole/moles:localName)) then ($PIRole/moles:localName) else ()}},for $CI in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgInvestigator/moles:dgCoInvestigator return element dgCoInvestigator {($CI/moles:dgMetadataID), ($CI/moles:roleName), ($CI/moles:abbreviation), ($CI/moles:contactDetails), for $CIRole in $CI/moles:dgRoleHolder order by $CIRole/moles:startDate empty least, $CIRole/moles:endDate empty least return element dgRoleHolder {if (exists(CIRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($CIRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($CIRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($CIRole/moles:dgPersonID)) then f:return-stub-person('person', string($CIRole/moles:dgPersonID/moles:repositoryIdentifier), string($CIRole/moles:dgPersonID/moles:localIdentifier)) else (), ($CIRole/moles:startDate), if (exists($CIRole/moles:endDate)) then ($CIRole/moles:endDate) else (), if (exists($CIRole/moles:localName)) then ($CIRole/moles:localName) else ()}}},if (exists($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact)) then (element dgTechnicalContact {($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgMetadataID), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:roleName), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:abbreviation), ($Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:contactDetails), for $TechConRole in $Act/moles:dgActivity/moles:dgActivityRole/moles:dgTechnicalContact/moles:dgRoleHolder order by $TechConRole/moles:startDate empty least, $TechConRole/moles:endDate empty least return element dgRoleHolder {if (exists($TechConRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($TechConRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($TechConRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($TechConRole/moles:dgPersonID)) then f:return-stub-person('person', string($TechConRole/moles:dgPersonID/moles:repositoryIdentifier), string($TechConRole/moles:dgPersonID/moles:localIdentifier)) else (), ($TechConRole/moles:startDate), if (exists($TechConRole/moles:endDate)) then ($TechConRole/moles:endDate) else (), if (exists($TechConRole/moles:localName)) then ($TechConRole/moles:localName) else ()}}) else (),if (exists($Act/dgActivity/dgActivityRole/dgProjectManager)) then (element dgProjectManager {($Act/dgActivity/dgActivityRole/dgProjectManager/dgMetadataID), ($Act/dgActivity/dgActivityRole/dgProjectManager/roleName), ($Act/dgActivity/dgActivityRole/dgProjectManager/abbreviation), ($Act/dgActivity/dgActivityRole/dgProjectManager/contactDetails), for $PMRole in $Act/dgActivity/dgActivityRole/dgProjectManager/dgRoleHolder order by $PMRole/startDate empty least, $PMRole/endDate empty least return element dgRoleHolder {if (exists($PMRole/moles:dgOrganisationID)) then f:return-stub-organisation('organisation', data($PMRole/moles:dgOrganisationID/moles:repositoryIdentifier), data($PMRole/moles:dgOrganisationID/moles:localIdentifier)) else if (exists($PMRole/moles:dgPersonID)) then f:return-stub-person('person', string($PMRole/moles:dgPersonID/moles:repositoryIdentifier), string($PMRole/moles:dgPersonID/moles:localIdentifier)) else (), ($PMRole/startDate), if (exists($PMRole/moles:endDate)) then ($PMRole/moles:endDate) else (), if (exists($PMRole/moles:localName)) then ($PMRole/moles:localName) else ()}}) else ()},for $RelDep in $Act/moles:dgActivity/moles:ActivityDeployment return element ActivityDeployment {($RelDep/moles:DateStart), if (exists($RelDep/moles:DateEnd)) then ($RelDep/moles:DateEnd) else (), ($RelDep/moles:dgMetadataID), f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)), f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)), for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier))}, (: </ActivityDeployment> :) if (exists($Act/dgActivityCoverage)) then ($Act/dgActivityCoverage) else (), if (exists($Act/dgActivityDuration)) then ($Act/dgActivityDuration) else ()} ,for $strkwrd in $Act/moles:dgStructuredKeyword return $strkwrd, if (exists($Act/moles:dgMetadataProvenance)) then $Act/moles:dgMetadataProvenance else (), if (exists($Act/moles:dgMetadataSecurity)) then $Act/moles:dgMetadataSecurity else ()})'''
17
18StubBDPTQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/dataproductiontool';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}}else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name}{($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $DPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgDataProductionTool!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return f:strip-namespace(element dgMetadataRecord {$DPT/dgMetadataID,element dgMetadataID {element schemeIdentifier {'NDG-B1'},$DPT/moles:dgMetadataID/moles:repositoryIdentifier,$DPT/moles:dgMetadataID/moles:localIdentifier},$DPT/moles:dgMetadataDescription,$DPT/moles:name,$DPT/moles:abbreviation,element dgDataProductionTool {$DPT/moles:contactDetails,if (exists($DPT/moles:dgModel)) then $DPT/moles:dgModel else $DPT/moles:dgInstrument,if (exists($DPT/moles:dgDPTRoles)) then element dgDPTRoles {'Roles are available, and will be added soon'} else(),for $RelDep in $DPT/moles:dgDataProductionTool/moles:DPTDeployment return element DPTDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-obsstn('observationstation', data($RelDep/moles:ObservationStationID/moles:repositoryIdentifier), data($RelDep/moles:ObservationStationID/moles:localIdentifier)),for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),$RelDep/moles:Coverage}},for $strkwrd in $DPT/moles:dgStructuredKeyword return $strkwrd,if (exists($DPT/moles:dgMetadataProvenance)) then $DPT/moles:dgMetadataProvenance else (),if (exists($DPT/moles:dgMetadataSecurity)) then $DPT/moles:dgMetadataSecurity else ()})'''
19
20StubBObsStnQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles/observationstation';declare namespace moles='http://ndg.nerc.ac.uk/moles';declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';declare function f:strip-namespace($e as element()) as element(){element {QName('', local-name($e))}{let $parent :=$e let $childcount := count($parent/*) return if ($childcount>0) then for $child in ($e/*) return f:strip-namespace($child) else (data($e))}};declare function f:return-stub-activity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}}else (for $SRAct in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRAct/moles:dgMetadataID),($SRAct/moles:dgMetadataDescription),($SRAct/moles:name),($SRAct/moles:abbreviation),element dgActivity {if (exists($SRAct/*/moles:dgActivityDataCollection)) then ($SRAct/*/moles:dgActivityDataCollection) else if (exists($SRAct/*/moles:dgActivityDataProject)) then ($SRAct/*/moles:dgActivityDataProject) else if (exists($SRAct/*/dgActivityDataCampaign)) then ($SRAct/moles:dgActivity/moles:dgActivityDataCampaign) else ($SRAct/moles:dgActivity/moles:dgActivityDataInvestigation),($SRAct/moles:dgActivity/moles:dgActivityCoverage),($SRAct/moles:dgActivity/moles:dgActivityDuration)}})};declare function f:return-stub-dataentity($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRDE/moles:dgMetadataID),($SRDE/moles:dgMetadataDescription),($SRDE/moles:name),($SRDE/moles:abbreviation),element dgDataEntity {($SRDE/moles:dgDataEntity/moles:dgDataSetType),($SRDE/moles:dgDataEntity/moles:dgDataGranule),($SRDE/moles:dgDataEntity/moles:dgDataSummary)}})};declare function f:return-stub-dpt($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRDPT in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$SRDPT/moles:dgMetadataID,$SRDPT/moles:dgMetadataDescription,$SRDPT/moles:name,$SRDPT/moles:abbreviation,$SRDPT/moles:logos,element dgDataProductionTool {$SRDPT/moles:dgDataProductionTool/moles:contactDetails,if (exists($SRDPT/moles:dgDataProductionTool/moles:dgModel)) then $SRDPT/moles:dgDataProductionTool/moles:dgModel else (),if (exists($SRDPT/moles:dgDataProductionTool/moles:dgInstrument)) then $SRDPT/moles:dgDataProductionTool/moles:dgInstrument else ()}})};declare function f:return-stub-obsstn($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $SRObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {($SRObsStn/moles:dgMetadataID),($SRObsStn/moles:dgMetadataDescription),($SRObsStn/moles:name),($SRObsStn/moles:abbreviation),element dgObservationStation {($SRObsStn/moles:dgObservationStation/moles:contactDetails),if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgLandStation)) then element dgLandStation {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgMooring)) then element dgMooring {''} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {''} else ()} else if (exists($SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform)) then $SRObsStn/moles:dgObservationStation/moles:dgMovingPlatform else ()}})};declare function f:return-stub-person($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $person in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgPerson[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name}{($person/moles:name),($person/moles:contactDetails),($person/moles:dgMetadataID)})};declare function f:return-stub-organisation($out-element-name as xs:string, $repid as xs:string, $locid as xs:string) as element(){let $found := count(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid]) return if ($found = 0) then element {$out-element-name} {element error {'not found'},element repositoryIdentifier {$repid},element localIdentifier {$locid}} else (for $org in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgOrganisation[moles:dgMetadataID/moles:repositoryIdentifier=$repid and moles:dgMetadataID/moles:localIdentifier=$locid] return element {$out-element-name} {$org/moles:dgMetadataID,$org/moles:name,$org/moles:abbreviation,$org/moles:contactDetails,$org/moles:logos})};for $ObsStn in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgObservationStation!='' and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return f:strip-namespace(element dgMetadataRecord {element dgMetadataID {element schemeIdentifier {'NDG-B1',$ObsStn/moles:dgMetadataID/moles:repositoryIdentifier,$ObsStn/moles:dgMetadataID/moles:localIdentifier},$ObsStn/moles:dgMetadataDescription,$ObsStn/moles:name,$ObsStn/moles:abbreviation,element dgObservationStation {$ObsStn/moles:dgObservationStation/moles:contactDetails,if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform)) then element dgStationaryPlatform {$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:position,if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring)) then element dgMooring {$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateStart,$ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dateEnd,for $DepositingCruise in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:DepositingCruise return f:return-stub-activity('depositingcruise', data($DepositingCruise/moles:dgMetadataID/moles:repositoryIdentifier), data($DepositingCruise/moles:dgMetadataID/moles:localIdentifier)),if (exists($ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/moles:dgStationGrouping)) then for $StationGrouping in $ObsStn/moles:dgObservationStation/moles:dgStationaryPlatform/moles:dgMooring/dgStationGrouping return f:return-stub-obsstn('stationgrouping', data($StationGrouping/moles:dgMetadataID/moles:repositoryIdentifier), data($StationGrouping/moles:dgMetadataID/moles:localIdentifier)) else ()} else if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup)) then element dgStationGroup {element dgGroupedStations {if (exists($ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStations)) then for $GroupedStation in $ObsStn/dgObservationStation/dgStationaryPlatform/dgStationGroup/dgGroupedStation/dgGroupedStations return f:return-stub-obsstn('dgGroupedStation', data($GroupedStation/moles:dgMetadataID/moles:repositoryIdentifier), data($GroupedStation/moles:dgMetadataID/moles:localIdentifier)) else ()}} else $ObsStn/moles:dgObservationStation/moles:dgLandStation} else $ObsStn/moles:dgObservationStation/moles:dgMovingPlatform},for $RelDep in $ObsStn/moles:dgObservationStation/moles:ObsStationDeployment return element ObsStationDeployment {$RelDep/moles:DateStart,$RelDep/moles:DateEnd,$RelDep/moles:dgMetadataID,f:return-stub-activity('activity', data($RelDep/moles:ActivityID/moles:repositoryIdentifier), data($RelDep/moles:ActivityID/moles:localIdentifier)),f:return-stub-dpt('dataproductiontool', data($RelDep/moles:DataProductionToolID/moles:repositoryIdentifier), data($RelDep/moles:DataProductionToolID/moles:localIdentifier)),for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord where $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:repositoryIdentifier=$RelDep/moles:dgMetadataID/moles:repositoryIdentifier and $DE/moles:dgDataEntity/moles:RelatedDeployment/moles:dgMetadataID/moles:localIdentifier=$RelDep/moles:dgMetadataID/moles:localIdentifier return f:return-stub-dataentity('dataentity', data($DE/moles:dgMetadataID/moles:repositoryIdentifier), data($DE/moles:dgMetadataID/moles:localIdentifier)),$RelDep/moles:Coverage}},for $strkwrd in $ObsStn/moles:dgStructuredKeyword return $strkwrd,if (exists($ObsStn/moles:dgMetadataProvenance)) then $ObsStn/moles:dgMetadataProvenance else (),if (exists($ObsStn/moles:dgMetadataSecurity)) then $ObsStn/moles:dgMetadataSecurity else ()})'''
21
22MOLESQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles';for $Moles in collection('/db/ndg_B_metadata')/dgMetadata/dgMetadataRecord[dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID'] return $Moles'''
23
24DublinCoreDEQuery = '''declare default element namespace 'http://ndg.nerc.ac.uk/moles';
25declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
26declare namespace dc='http://purl.org/dc/elements/1.1/';
27declare namespace oai_dc='http://www.openarchives.org/OAI/2.0/oai_dc';
28declare variable $targetCollection as xs:string {'/db/ndg_B_metadata'};
29declare variable $gcmd_science_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html'};
30declare variable $gcmd_project_valids as xs:string {'http://gcmd.gsfc.nasa.gov/Resources/valids/projects.html'};
31declare variable $cf_standard_names as xs:string {'http://www.cgd.ucar.edu/cms/eaton/cf-metadata/standard_name.html'};
32declare variable $iso_topic_list as xs:string {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'};
33
34for $DE in collection($targetCollection)/dgMetadata/dgMetadataRecord[dgDataEntity!='' and dgMetadataID/schemeIdentifier='NDG-B0' and dgMetadataID/repositoryIdentifier='RepositoryID' and dgMetadataID/localIdentifier='LocalID']
35return
36element oai_dc:dc {
37attribute xsi:schemaLocation {'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'},
38element dc:title {string($DE/name)},
39element dc:type {'Dataset'},
40element dc:identifier {concat($DE/dgMetadataID/repositoryIdentifier, ':DC:', $DE/dgMetadataID/localIdentifier)},
41element dc:description {string($DE/dgMetadataDescription/abstract/abstractText)},
42element dc:date
43{
44if (exists($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)) then
45for $updatedate in ($DE/(dgMetadataProvenance | DataProvenance)/RecordUpdate/UpdateDate)
46order by xs:dateTime($updatedate)
47return data($updatedate[1])
48else
49string($DE/(dgMetadataProvenance | DataProvenance)/RecordCreation/CreatedDate)
50},
51for $StructuredKeyword in distinct-values($DE/dgStructuredKeyword [dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids or dgValidTermID/ParentListID=$iso_topic_list ]//dgValidTerm)
52order by $StructuredKeyword
53return
54element dc:subject {string($StructuredKeyword)},
55
56for $StructuredKeyword1 in distinct-values($DE/dgDataEntity/dgDataSummary/dgParameterSummary/dgStdParameterMeasured[dgValidTermID/ParentListID=$cf_standard_names or dgValidTermID/ParentListID=$gcmd_science_valids or dgValidTermID/ParentListID=$gcmd_project_valids]//dgValidTerm)
57order by $StructuredKeyword1
58return
59element dc:subject {string($StructuredKeyword1)},
60for $DataCreatorRole in $DE/dgDataEntity/dgDataRoles/dgDataCreator/dgRoleHolder
61order by $DataCreatorRole/startDate empty least
62return
63for $DataCreatorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
64[(dgMetadataID/schemeIdentifier='NDG-B0'
65and dgMetadataID/repositoryIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
66and dgMetadataID/localIdentifier=$DataCreatorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
67return
68element dc:creator {
69if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then
70(string($DataCreatorRoleHolder/name))
71else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then
72(string(concat(string($DataCreatorRoleHolder/name/initials), ' ', string($DataCreatorRoleHolder/name/familyName))))
73else ('empty content')
74},
75for $DataCuratorRole in $DE/dgDataEntity/dgDataRoles/dgDataCurator/dgRoleHolder[not(exists(endDate)) or endDate='']
76order by $DataCuratorRole/startDate empty least
77return
78for $DataCuratorRoleHolder in collection($targetCollection)/dgMetadata/(dgOrganisation | dgPerson)
79[(dgMetadataID/schemeIdentifier='NDG-B0'
80and dgMetadataID/repositoryIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/repositoryIdentifier
81and dgMetadataID/localIdentifier=$DataCuratorRole/(dgOrganisationID | dgPersonID)/localIdentifier)]
82return
83element dc:publisher {
84if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then
85(string($DataCuratorRoleHolder/name))
86else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then
87(string(concat(string($DataCuratorRoleHolder/name/initials), ' ', string($DataCuratorRoleHolder/name/familyName))))
88else ('empty content')
89}
90}'''
91
92DIFQuery = '''declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/';
93declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
94declare namespace moles='http://ndg.nerc.ac.uk/moles';
95declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions';
96
97for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[
98exists('moles:dgDataEntity')
99and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
100and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID'
101and moles:dgMetadataID/moles:localIdentifier='LocalID']
102return
103element DIF {
104attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'},
105element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, ':DIF:', $DE/moles:dgMetadataID/moles:localIdentifier)},
106element Entry_Title {string($DE/moles:name)},
107element Data_Set_Citation {
108for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1]
109return
110for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
111and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier
112and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)]
113return
114element Data_Creator {
115if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then
116string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))
117else
118string($DataCreatorRoleHolder/moles:abbreviation)
119},
120element Dataset_Title {string($DE/moles:name)}
121},
122for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | moles:dgStdParameterMeasured)[moles:dgValidTermID/moles:ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html' and moles:ListLevel = 0])
123return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then
124element Parameters {
125element Category {string($StructuredKeyword/*/moles:dgValidTerm)},
126if (exists($StructuredKeyword//moles:dgValidSubterm)
127and $StructuredKeyword//moles:dgValidSubterm != ''
128and $StructuredKeyword//moles:dgValidSubterm != ' ') then
129for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)]
130where exists($Subterm/moles:dgValidSubterm)
131order by $Subterm/moles:ListLevel
132return
133if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
134else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
135else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
136else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
137else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}
138else()
139}
140else(),
141for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[moles:dgValidTermID/moles:ParentListID='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'])
142return
143element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)},
144for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[
145moles:dgValidTermID/moles:ParentListID!='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_parameters.html'
146and
147moles:dgValidTermID/moles:ParentListID!='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'
148]/moles:dgValidTerm)
149return element Keyword {string($Keyword)},
150for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)
151return
152element Sensor_Name {
153for $DepDPTAbbrev in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:abbreviation))
154return element Short_Name {data($DepDPTAbbrev)},
155for $DepDPTName in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:name))
156return element Long_Name {data($DepDPTName)}
157},
158for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID)
159return
160element Source_Name {
161for $DepObsStnAbbrev in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:abbreviation))
162return element Short_Name {data($DepObsStnAbbrev)},
163for $DepObsStnName in distinct-values((collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:name))
164return element Long_Name {data($DepObsStnName)}
165},
166for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange)
167return
168element Temporal_Coverage
169{
170element Start_Date {data($TemporalRange/moles:DateRangeStart)},
171element End_Date {data($TemporalRange/moles:DateRangeEnd)}
172},
173for $TemporalTerm in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea/moles:dgValidTerm)
174return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},
175for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure)
176return element Data_Set_Progress {data($Data_Set_Progress)},
177for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox)
178return
179element Spatial_Coverage {
180element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)},
181element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)},
182element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)},
183element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)}
184},
185for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[moles:dgValidTermID/moles:ParentListID='http://gcmd.gsfc.nasa.gov/Resources/valids/gcmd_locations.html'])
186return element Location {$Location},
187for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID)
188return
189element Project {
190for $DepActAbbrev in distinct-values(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:abbreviation)
191return
192element Short_Name {data($DepActAbbrev)},
193for $DepActName in distinct-values(collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:name)
194return
195element Long_Name {data($DepActName)}
196},
197if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then
198for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule
199return
200element Access_Constraints {
201if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then
202concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ')
203else (),
204if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then
205concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true()))
206else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then
207data($DG/moles:accessControlPolicy/moles:accessControlPolicyText)
208else
209for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition
210return
211if (exists($securityCondition/moles:conditionExplanationText)) then
212concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText))
213else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority))
214}
215else (),
216if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then
217for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder
218order by $DataCreatorRole/moles:startDate empty least
219return
220for $DataCreatorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson)
221[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
222and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier
223and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)]
224return
225element Originating_Center {
226if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then
227(string($DataCreatorRoleHolder/moles:name))
228else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then
229(string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))))
230else ('empty content')
231}
232else (),
233for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate='']
234return
235for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
236and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier
237and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)]
238return
239element Data_Center {
240element Data_Center_Name {
241element Short_Name {
242if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
243string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))
244else
245string($DataCuratorRoleHolder/moles:abbreviation)
246},
247element Long_Name {
248if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
249string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))
250else string($DataCuratorRoleHolder/moles:name)
251}
252},
253if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then
254element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)}
255else (),
256for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID
257return
258element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, ':', $DGID/moles:schemeIdentifier, ':', $DGID/moles:localIdentifier)},
259element Personnel {
260element Role {'Data Center Contact'},
261if (exists($DataCuratorRoleHolder/name/knownAs)) then
262element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)}
263else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then
264element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)}
265else (),
266element Last_Name {
267if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then
268string($DataCuratorRoleHolder/moles:name/moles:familyName)
269else string($DataCuratorRoleHolder/moles:name)
270},
271if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then
272element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)}
273else
274if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then
275(element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)})
276else (),
277if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then
278element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)}
279else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then
280element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}
281else (),
282if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then
283element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)}
284else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then
285element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}
286else (),
287if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then
288element Contact_Address {
289for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline
290return element Address {data($addressline)},
291if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then
292element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}
293else (),
294if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then
295element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)}
296else (),
297if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then
298element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)}
299else ()
300}
301else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then
302element Contact_Address {
303for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline
304return element address {data($addressline)},
305if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then
306element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}
307else (),
308if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then
309element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)}
310else (),
311if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then
312element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)}
313else ()
314}
315else ()
316}
317},
318element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)},
319element Related_URL {
320element URL_Content_Type {'NDG_B_SERVICE'},
321element URL {data($DE/moles:dgMetadataID/moles:repositoryIdentifier)},
322element Description {'The NDG service for browsing metadata.'}
323},
324for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule
325return
326if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then
327(element Related_URL {
328element URL_Content_Type {'NDG_A_SERVICE'},
329if (exists($DG/instance/URI)) then
330element URL {escape-uri($DG/instance/URI, true())}
331else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
332element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())}
333else ($DG/moles:dataModelID/moles:repositoryIdentifier),
334element Description {'The NDG service delivering data via NDG A metadata.'}
335},
336element Related_URL {
337element URL_Content_Type {'GET DATA > CSML'},
338if (exists($DG/instance)) then
339element URL {escape-uri($DG/instance/URI, true())}
340else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
341element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())}
342else (),
343element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'}
344})
345else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then
346(element Related_URL {
347element URL_Content_Type {'NDG_A_SERVICE'},
348if (exists($DG/instance)) then
349element URL {escape-uri($DG/instance/URI, true())}
350else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
351element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}
352else (),
353element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}
354},
355element Related_URL {
356element URL_Content_Type {'GET DATA > DX'},
357if (exists($DG/instance)) then
358element URL {escape-uri($DG/instance/URI, true())}
359else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then
360element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())}
361else (),
362element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'}
363})
364else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then
365element Related_URL {
366element URL {data($DG/moles:instance/moles:URI)},
367if (exists($DG/moles:instance/moles:instanceComment)) then
368element Description {data($DG/moles:instance/moles:instanceComment)}
369else
370element Description {'URL to aid in delivering data. Note that this may point directly to the data or, more likely, point to the web site of the curator.'}
371}
372else (),
373for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)
374return
375element Related_URL {
376element URL {data($RelURL_Desc)},
377element Description {concat(data($RelURL_Desc/moles:name), ' - ', data($RelURL_Desc/moles:notes))}
378},
379element Metadata_Name {'[CEOS IDN DIF]'},
380element Metadata_Version {'9.4'},
381if (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then
382element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)}
383else (),
384for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate
385return
386element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))},
387if (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then
388element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)}
389else ()
390}'''
391
392ISO19139Query = '''declare default element namespace 'http://www.isotc211.org/2005/gmd'; declare namespace moles='http://ndg.nerc.ac.uk/moles'; declare namespace gco='http://www.isotc211.org/2005/gco'; declare namespace gmd='http://www.isotc211.org/2005/gmd'; declare namespace gml='http://www.opengis.net/gml'; declare namespace xlink='http://www.w3.org/1999/xlink'; declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance'; declare namespace f='http://ndg.nerc.ac.uk/moles/localfunctions'; for $DE in collection('/db/ndg_B_metadata')/moles:dgMetadata/moles:dgMetadataRecord[ exists(moles:dgDataEntity) and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier='RepositoryID' and moles:dgMetadataID/moles:localIdentifier='LocalID'] return element MD_Metadata {attribute xsi:schemaLocation {'http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/metadataEntity.xsd'}, element fileIdentifier {element gco:CharacterString {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, ':ISO19115:', $DE/moles:dgMetadataID/moles:localIdentifier)}}, element language {element gmd:LanguageCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCode'}, attribute codeListValue {'eng'}, 'English'}}, element hierarchyLevel {element MD_ScopeCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode'}, attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode_dataset'}, 'dataset'}}, for $parent in $DE/moles:dgRelatedDataEntity[moles:RelationID/moles:dgValidTerm='is-part-of'] return element parentIdentifier {element gco:CharacterString {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, ':', $DE/moles:dgMetadataID/moles:localIdentifier, ':', $DE/moles:dgMetadataID/moles:localIdentifier)}}, for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''] return for $DataCuratorRoleHolder in collection('/db/ndg_B_metadata')/moles:dgMetadata/(moles:dgPerson | moles:dgOrganisation)[ moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/(moles:dgPersonID | moles:dgOrganisationID)/moles:repositoryIdentifier and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/(moles:dgPersonID | moles:dgOrganisationID)/moles:localIdentifier] return element contact {element CI_ResponsibleParty {if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then element organisationName {element gco:CharacterString {string($DataCuratorRoleHolder/moles:name)}}else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then element individualName {element gco:CharacterString {string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))}}else ('empty content') , element positionName {if (exists($DataCuratorRoleHolder/moles:localName)) then element gco:CharacterString {$DataCuratorRoleHolder/moles:localName}else if (exists($DataCuratorRole/moles:roleName)) then element gco:CharacterString {$DataCuratorRole/moles:roleName}else element gco:CharacterString {'Curator'}}, element contactInfo {element gmd:CI_Contact {if (exists($DataCuratorRole/moles:contactDetails/moles:telephone or $DataCuratorRole/moles:contactDetails/moles:fax or $DataCuratorRoleHolder/moles:contactDetails/moles:telephone or $DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then element phone {element gmd:CI_Telephone {if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then element voice {element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:telephone)}}else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then element voice {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}}else (), if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then element facsimile {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}}else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then element facsimile {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}}else () }} else (), element address {element gmd:CI_Address {if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:addressline)) then for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline return element deliveryPoint {element gco:CharacterString {data($addressline)}}else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline)) then for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline return element deliveryPoint {element gco:CharacterString {data($addressline)}}else (), if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then element city {element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}}else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then element city {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}}else (), if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then element electronicMailAddress {element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:eMail)}}else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then element electronicMailAddress {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}}else () }}}}, element role {element CI_RoleCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode'}, attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode_custodian'}, if (exists($DataCuratorRole/moles:localName)) then data($DataCuratorRole/moles:localName) else if (exists($DataCuratorRoleHolder/moles:localName)) then data($DataCuratorRoleHolder/moles:localName) else 'Curator' }}}}, element dateStamp {element gco:Date {adjust-date-to-timezone(current-date())}}, element metadataStandardName {element gco:CharacterString {'ISO 19115:2003'}}, element metadataStandardVersion {element gco:CharacterString {'2003'}}, element identificationInfo {element gmd:MD_DataIdentification {element citation {element gmd:CI_Citation {element title {element gco:CharacterString {data($DE/moles:name)}}, if (exists($DE/moles:abbreviation) and not(empty($DE/moles:abbreviation))) then element alternateTitle {element gco:CharacterString {data($DE/moles:abbreviation)}}else (), element date {if (exists($DE/(moles:DataProvenance | moles:dgMetadataProvenance)/moles:RecordCreation/moles:CreatedDate)) then element gmd:CI_Date {element date {element gco:Date {adjust-date-to-timezone(data($DE/(moles:DataProvenance | moles:dgMetadataProvenance)/moles:RecordCreation/moles:CreatedDate))}}, element dateType {element CI_DateTypeCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/moles:gmxCodelists.xml#CI_DateTypeCode'}, attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode_creation' }, 'Creation'}}}else attribute gco:nilReason {'unknown'}}}}, element abstract {element gco:CharacterString {data($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}}, element language {element gmd:LanguageCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCode'}, attribute codeListValue {'eng'}, 'English' }}, for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[dgValidTermID/moles:ParentListID='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode']) return element topicCategory {element gmd:MD_TopicCategoryCode {attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'}, attribute codeListValue {string($ISOTopicCategory/moles:dgValidTerm)}, string($ISOTopicCategory/moles:dgValidTerm)}}, if (exists($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage)) then element extent {element gmd:EX_Extent {(: add bounding boxes:) for $geoBBox in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox return element geographicElement {element EX_GeographicBoundingBox {element westBoundLongitude {element gco:Decimal {data($geoBBox/moles:LimitWest)}}, element eastBoundLongitude {element gco:Decimal {data($geoBBox/moles:LimitEast)}}, element southBoundLatitude {element gco:Decimal {data($geoBBox/moles:LimitSouth)}}, element northBoundLatitude {element gco:Decimal {data($geoBBox/moles:LimitNorth)}}}}, for $geoArea in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea return element geographicElement {element EX_GeographicDescription {element geographicIdentifier {element gmd:RS_Identifier {element gco:CharacterString {element code {data(dgArea/dgValidTerm)}}, element gco:CharacterString {element codeSpace {data(dgArea/dgValidTermID/ParentListID)}}}}}}}}else()}}}'''
Note: See TracBrowser for help on using the repository browser.