Ignore:
Timestamp:
06/03/07 14:38:37 (13 years ago)
Author:
ko23
Message:

Refactoring - working versions. Still slow though.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/ndg_xqueries.py

    r2228 r2236  
    12981298 
    12991299ISO19139Query = '''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()}}}''' 
     1300 
     1301DIFQuery = '''import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
     1302import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery'; 
     1303declare default element namespace 'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/'; 
     1304declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  
     1305declare namespace moles='http://ndg.nerc.ac.uk/moles'; 
     1306declare variable $targetCollection as xs:string {'TargetCollection'}; 
     1307declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
     1308declare variable $localIdentifier as xs:string {'LocalID'}; 
     1309 
     1310for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     1311    exists('moles:dgDataEntity')  
     1312    and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  
     1313    and moles:dgMetadataID/moles:repositoryIdentifier=$repositoryIdentifier 
     1314    and moles:dgMetadataID/moles:localIdentifier=$localIdentifier] 
     1315return 
     1316element DIF { 
     1317    attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'}, 
     1318    element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'DIF', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)}, 
     1319    element Entry_Title {string($DE/moles:name)}, 
     1320    element Data_Set_Citation { 
     1321            for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1] 
     1322        return  
     1323            for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1324                   and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
     1325                   and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
     1326            return  
     1327                    element Data_Creator { 
     1328                if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then  
     1329                    string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))) 
     1330                else  
     1331                   string($DataCreatorRoleHolder/moles:abbreviation) 
     1332                    }, 
     1333        element Dataset_Title {string($DE/moles:name)} 
     1334    }, 
     1335    for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | moles:dgStdParameterMeasured)[(voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID))]) 
     1336        return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then  
     1337            element Parameters { 
     1338            element Category {string($StructuredKeyword/*/moles:dgValidTerm)}, 
     1339            if (exists($StructuredKeyword//moles:dgValidSubterm)  
     1340                and $StructuredKeyword//moles:dgValidSubterm != ''  
     1341                and $StructuredKeyword//moles:dgValidSubterm != ' ') then  
     1342            for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)] 
     1343                where exists($Subterm/moles:dgValidSubterm) 
     1344                order by $Subterm/moles:ListLevel 
     1345                return  
     1346                    if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1347                    else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1348                    else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1349                    else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1350                    else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)} 
     1351            else() 
     1352                } 
     1353        else(), 
     1354    for $StructuredKeyword in ($DE//(moles:dgStructuredKeyword | moles:dgDataEntity/moles:dgDataSummary/moles:dgParameterSummary/moles:dgStdParameterMeasured)[voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) or voclib:spot-vocab($voclib:gcmd_science_valids_deprecated, moles:dgValidTermID/moles:ParentListID) and (not(exists(moles:ListLevel)) or moles:ListLevel=0)]) 
     1355    return 
     1356        element Parameters {data($StructuredKeyword/moles:dgValidTerm)}, 
     1357    for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)]) 
     1358        return  
     1359            element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)}, 
     1360    for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[ 
     1361    not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID) 
     1362    or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) 
     1363    or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) 
     1364    )]/moles:dgValidTerm) 
     1365    return element Keyword {string($Keyword)},  
     1366    for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)   
     1367    return  
     1368        element Sensor_Name { 
     1369            for $DepDPTAbbrev in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:abbreviation)) 
     1370                return element Short_Name {data($DepDPTAbbrev)}, 
     1371            for $DepDPTName in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepDPT/moles:repositoryIdentifier and moles:localIdentifier=$DepDPT/moles:localIdentifier]]/moles:name)) 
     1372                return element Long_Name {data($DepDPTName)} 
     1373            }, 
     1374    for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID) 
     1375    return  
     1376        element Source_Name { 
     1377            for $DepObsStnAbbrev in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:abbreviation)) 
     1378                return element Short_Name {data($DepObsStnAbbrev)}, 
     1379            for $DepObsStnName in ((collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepObsStn/moles:repositoryIdentifier and moles:localIdentifier=$DepObsStn/moles:localIdentifier]]/moles:name)) 
     1380                return element Long_Name {data($DepObsStnName)} 
     1381            }, 
     1382    for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange) 
     1383        return  
     1384            element Temporal_Coverage 
     1385                { 
     1386                element Start_Date {data($TemporalRange/moles:DateRangeStart)}, 
     1387                element End_Date {data($TemporalRange/moles:DateRangeEnd)} 
     1388                }, 
     1389    for $TemporalTerm in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_chronostratigraphic_valids, moles:dgValidTermID/moles:ParentListID)]/moles:dgValidTerm) 
     1390        return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},  
     1391    for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure) 
     1392        return element Data_Set_Progress {data($Data_Set_Progress)}, 
     1393    for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox) 
     1394    return  
     1395        element Spatial_Coverage { 
     1396                element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)}, 
     1397                element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)}, 
     1398                element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)}, 
     1399                element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)} 
     1400            }, 
     1401    for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)]) 
     1402        return element Location {$Location},  
     1403    for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID) 
     1404    return  
     1405        element Project { 
     1406            for $DepActAbbrev in (collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:abbreviation) 
     1407                return  
     1408                    element Short_Name {data($DepActAbbrev)}, 
     1409            for $DepActName in (collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[moles:dgMetadataID[moles:schemeIdentifier='NDG-B0' and moles:repositoryIdentifier=$DepAct/moles:repositoryIdentifier and moles:localIdentifier=$DepAct/moles:localIdentifier]]/moles:name) 
     1410                return  
     1411                    element Long_Name {data($DepActName)} 
     1412            }, 
     1413    if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then  
     1414            for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
     1415                return  
     1416                                element Access_Constraints { 
     1417                            if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then  
     1418                                concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ') 
     1419                            else (), 
     1420                            if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then 
     1421                                concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true())) 
     1422                            else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then 
     1423                                data($DG/moles:accessControlPolicy/moles:accessControlPolicyText) 
     1424                             else  
     1425                                 for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition 
     1426                                 return 
     1427                                     if (exists($securityCondition/moles:conditionExplanationText)) then 
     1428                                         concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText)) 
     1429                                     else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority)) 
     1430                        } 
     1431                else (), 
     1432    if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then 
     1433        for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder  
     1434            order by $DataCreatorRole/moles:startDate empty least 
     1435                        return  
     1436                    for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
     1437                                        [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1438                                        and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier 
     1439                                        and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)] 
     1440                    return  
     1441                            element Originating_Center { 
     1442                    if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then 
     1443                        (string($DataCreatorRoleHolder/moles:name)) 
     1444                    else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then 
     1445                        (string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))) 
     1446                    else ('empty content') 
     1447                } 
     1448    else (), 
     1449    for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''] 
     1450        return  
     1451            for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1452               and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier 
     1453               and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)] 
     1454                return  
     1455                    element Data_Center { 
     1456                element Data_Center_Name { 
     1457                        element Short_Name { 
     1458                            if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1459                        string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     1460                   else  
     1461                       string($DataCuratorRoleHolder/moles:abbreviation) 
     1462                }, 
     1463            element Long_Name { 
     1464                    if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1465                        string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     1466                    else string($DataCuratorRoleHolder/moles:name) 
     1467                } 
     1468            }, 
     1469            if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then  
     1470                    element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)} 
     1471            else (), 
     1472            for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID 
     1473            return  
     1474                element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, '__', $DGID/moles:schemeIdentifier, '__', $DGID/moles:localIdentifier)}, 
     1475            element  Personnel { 
     1476                    element Role {'Data Center Contact'}, 
     1477                    if (exists($DataCuratorRoleHolder/name/knownAs)) then  
     1478                        element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)} 
     1479                    else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1480                        element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)} 
     1481                     else (),                     
     1482                     element Last_Name { 
     1483                              if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then  
     1484                                  string($DataCuratorRoleHolder/moles:name/moles:familyName) 
     1485                    else string($DataCuratorRoleHolder/moles:name) 
     1486                        }, 
     1487                    if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then  
     1488                        element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)} 
     1489                    else  
     1490                        if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then  
     1491                                (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}) 
     1492                               else (), 
     1493                    if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then  
     1494                        element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)} 
     1495                    else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then  
     1496                                element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)} 
     1497                     else (), 
     1498                    if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then  
     1499                        element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)} 
     1500                    else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then  
     1501                                element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)} 
     1502                            else (), 
     1503                    if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then  
     1504                        element Contact_Address { 
     1505                            for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline 
     1506                                return element Address {data($addressline)}, 
     1507                                                        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then  
     1508                            element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)} 
     1509                        else (), 
     1510                        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then  
     1511                            element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)} 
     1512                        else (), 
     1513                         if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then  
     1514                             element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)} 
     1515                         else () 
     1516                         } 
     1517                    else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then  
     1518                        element Contact_Address { 
     1519                            for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline 
     1520                                return element Address {data($addressline)}, 
     1521                                                            if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then  
     1522                                element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)} 
     1523                            else (), 
     1524                            if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then  
     1525                                element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)} 
     1526                            else (), 
     1527                             if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then  
     1528                                 element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)} 
     1529                             else () 
     1530                         } 
     1531                    else () 
     1532                     } 
     1533                        }, 
     1534    element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}, 
     1535    element Related_URL  { 
     1536        element URL_Content_Type {'NDG_B_SERVICE'}, 
     1537        element URL {data($DE/moles:dgMetadataID/moles:repositoryIdentifier)}, 
     1538        element Description {'The NDG service for browsing metadata.'} 
     1539        }, 
     1540    for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
     1541        return 
     1542            if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then  
     1543                       (element Related_URL { 
     1544                               element URL_Content_Type {'NDG_A_SERVICE'}, 
     1545                               if (exists($DG/instance/URI)) then 
     1546                                   element URL {escape-uri($DG/instance/URI, true())} 
     1547                               else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1548                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())} 
     1549                               else ($DG/moles:dataModelID/moles:repositoryIdentifier), 
     1550                             element Description {'The NDG service delivering data via NDG A metadata.'} 
     1551                           }, 
     1552                      element Related_URL { 
     1553                               element URL_Content_Type {'GET DATA > CSML'}, 
     1554                               if (exists($DG/instance)) then 
     1555                                   element URL {escape-uri($DG/instance/URI, true())} 
     1556                               else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1557                                   element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&datasetID=', true())} 
     1558                               else (), 
     1559                             element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'} 
     1560                           }) 
     1561            else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then  
     1562                           (element Related_URL {  
     1563                                   element URL_Content_Type {'NDG_A_SERVICE'}, 
     1564                               if (exists($DG/instance)) then 
     1565                                   element URL {escape-uri($DG/instance/URI, true())} 
     1566                               else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1567                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
     1568                               else (), 
     1569                             element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
     1570                               }, 
     1571                           element Related_URL { 
     1572                               element URL_Content_Type {'GET DATA > DX'}, 
     1573                               if (exists($DG/instance)) then 
     1574                                   element URL {escape-uri($DG/instance/URI, true())} 
     1575                               else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1576                                   element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
     1577                               else (), 
     1578                             element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
     1579                               }) 
     1580            else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then  
     1581                       element Related_URL { 
     1582                             element URL {data($DG/moles:instance/moles:URI)}, 
     1583                             if (exists($DG/moles:instance/moles:instanceComment)) then  
     1584                                     element Description {data($DG/moles:instance/moles:instanceComment)}            
     1585                             else  
     1586                                     element 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.'} 
     1587                          } 
     1588        else (), 
     1589        for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)  
     1590        return 
     1591                       element Related_URL { 
     1592                             element URL {data($RelURL_Desc)}, 
     1593                         element Description {concat(data($RelURL_Desc/moles:name), ' - ', data($RelURL_Desc/moles:notes))}            
     1594                       }, 
     1595    element Metadata_Name {'[CEOS IDN DIF]'}, 
     1596    element Metadata_Version {'9.4'}, 
     1597    if  (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then  
     1598            element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)} 
     1599    else (), 
     1600    for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate 
     1601    return   
     1602        element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))}, 
     1603    if  (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then  
     1604            element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)} 
     1605    else () 
     1606        }''' 
Note: See TracChangeset for help on using the changeset viewer.