Changeset 2358


Ignore:
Timestamp:
02/04/07 08:36:07 (12 years ago)
Author:
ko23
Message:

Base NDG2DIF bugfix + Python lib (no XQueryLib dependence)

Location:
TI07-MOLES/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/DIF/XQuery/DIF2MOLES.xquery

    r2291 r2358  
    99 
    1010(: Replacable parameters :) 
     11declare variable $targetCollection as xs:string {'/db/discovery'}; 
     12declare variable $input_repository as xs:string {'Input_Repository_Code'}; 
     13declare variable $input_repository_local as xs:string {'Input_Repository_LocalID'}; 
     14declare variable $input_entry_id as xs:string {'GEOARCHIVES'}; 
     15declare variable $localIdentifier as xs:string {'GEOARCHIVES'}; 
     16 
     17declare variable $output_local_id as xs:string {'Output_LocalID'}; 
     18(: Keep 
    1119declare variable $targetCollection as xs:string {'TargetCollection'}; 
    1220declare variable $input_repository as xs:string {'Input_Repository_Code'}; 
     
    1422declare variable $input_entry_id as xs:string {'Input_Entry_ID'}; 
    1523declare variable $output_local_id as xs:string {'Output_LocalID'}; 
    16  
     24:) 
    1725for $DIF in collection($targetCollection)/dif:DIF[dif:Entry_ID=$input_entry_id] 
    1826return 
     
    3846element metadataDescriptionLastUpdated {current-date()}                 , 
    3947element abstract { 
    40 element abstractText {string($DIF/dif:Summary)} 
     48element abstractText {string($DIF/dif:Summary)}, 
     49for $descOnline in $DIF/dif:Related_URL 
     50return 
     51element descriptionSection { 
     52element descriptionOnlineReference { 
     53element dgSimpleLink {escape-uri(data($descOnline/dif:URL), true())}}, 
     54if (exists($descOnline/dif:URL_Content_Type)) then  
     55element dgReferenceName {data($descOnline/dif:URL)} 
     56else () 
     57} 
    4158} 
    4259}, 
     
    6279}, 
    6380element dgStdParameterMeasured { 
    64 element dgValidTerm {string($parameter/dif:Category)}, 
     81if ($parameter/dif:Category!='') then element dgValidTerm {string($parameter/dif:Category)} 
     82else  element dgValidTerm {'unknown'}, 
    6583element dgValidTermID { 
    6684element ParentListID {concat($voclib:gcmd_science_valids_categories, '/current')}, 
     
    6886}, 
    6987element dgValidSubterm { 
    70 element dgValidTerm {string($parameter/dif:Topic)}, 
     88if ($parameter/dif:Topic!='') then element dgValidTerm {string($parameter/dif:Topic)} 
     89else  element dgValidTerm {'unknown'}, 
    7190element dgValidTermID { 
    7291element ParentListID {concat($voclib:gcmd_science_valids_topics, '/current')}, 
    73 element TermID {escape-uri($parameter/dif:Category, true())} 
     92element TermID {escape-uri($parameter/dif:Topic, true())} 
    7493}, 
    7594element dgValidSubterm { 
    76 element dgValidTerm {string($parameter/dif:Term)}, 
     95if ($parameter/dif:Term!='') then element dgValidTerm {string($parameter/dif:Term)} 
     96else  element dgValidTerm {'unknown'}, 
    7797element dgValidTermID { 
    7898element ParentListID {concat($voclib:gcmd_science_valids_terms, '/current')}, 
    7999element TermID {escape-uri($parameter/dif:Term, true())} 
    80100}, 
    81 if (exists($parameter/dif:Variable)) then 
     101if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then 
    82102element dgValidSubterm { 
    83103element dgValidTerm {string($parameter/dif:Variable)}, 
     
    86106element TermID {escape-uri($parameter/dif:Variable, true())} 
    87107}, 
    88 if (exists($parameter/dif:Detailed_Variable)) then 
     108if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then 
    89109element dgValidSubterm { 
    90110element dgValidTerm {string($parameter/dif:Detailed_Variable)}, 
     
    106126element ParameterName { 
    107127concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)), 
    108 if (exists($parameter/dif:Variable)) then 
     128if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then 
    109129concat(' > ', string($parameter/dif:Variable)) 
    110130else (), 
    111 if (exists($parameter/dif:Detailed_Variable)) then 
     131if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then 
    112132concat(' > ', string($parameter/dif:Detailed_Variable)) 
    113133else () 
     
    115135element ParameterAbbreviation { 
    116136concat (string($parameter/dif:Category), ' > ', string($parameter/dif:Topic), ' > ', string($parameter/dif:Term)), 
    117 if (exists($parameter/dif:Variable)) then 
     137if (exists($parameter/dif:Variable) and $parameter/dif:Variable!='') then 
    118138concat(' > ', string($parameter/dif:Variable)) 
    119139else (), 
    120 if (exists($parameter/dif:Detailed_Variable)) then 
     140if (exists($parameter/dif:Detailed_Variable) and $parameter/dif:Detailed_Variable!='') then 
    121141concat(' > ', string($parameter/dif:Detailed_Variable)) 
    122142else () 
     
    193213return 
    194214element dgRoleHolder { 
    195 element dgOrganisationID { 
     215element dgMetadataID { 
    196216element schemeIdentifier {'NDG-B0'}, 
    197217element repositoryIdentifier {$input_repository}, 
  • TI07-MOLES/trunk/DIF/XQuery/NDG-DIF.xquery

    r2302 r2358  
    44declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';  
    55declare namespace moles='http://ndg.nerc.ac.uk/moles'; 
     6(: Keep 
    67declare variable $targetCollection as xs:string {'TargetCollection'}; 
    78declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
    89declare variable $localIdentifier as xs:string {'LocalID'}; 
     10:) 
     11declare variable $targetCollection as xs:string {'/db/discovery'}; 
     12declare variable $repositoryIdentifier as xs:string {'grid.bodc.nerc.ac.uk'}; 
     13declare variable $localIdentifier as xs:string {'neodc.nerc.ac.uk:DIF:NEODC_NCAVEO_LCM2000'}; 
    914 
    1015for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
     
    137142                                for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
    138143                                                [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    139                                                 and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier 
    140                                                 and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)] 
     144                                                and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
     145                                                and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
    141146                                return  
    142147                                        element Originating_Center { 
     
    148153                                } 
    149154        else (), 
    150         for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''] 
    151             return  
    152                 for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    153                    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier 
    154                    and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)] 
    155                     return  
    156                         element Data_Center { 
    157                         element Data_Center_Name { 
    158                                 element Short_Name { 
    159                                     if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    160                                     string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
    161                             else  
    162                                 string($DataCuratorRoleHolder/moles:abbreviation) 
    163                             }, 
    164                         element Long_Name { 
    165                                 if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    166                                     string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
    167                                 else string($DataCuratorRoleHolder/moles:name) 
    168                             } 
    169                         }, 
    170                         if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then  
    171                                 element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)} 
    172                         else (), 
    173                         for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID 
    174                         return  
    175                             element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, '__', $DGID/moles:schemeIdentifier, '__', $DGID/moles:localIdentifier)}, 
    176                         element  Personnel { 
    177                                 element Role {'Data Center Contact'}, 
    178                                 if (exists($DataCuratorRoleHolder/name/knownAs)) then  
    179                                     element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)} 
    180                                 else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    181                                     element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)} 
    182                                  else (),                                        
    183                                  element Last_Name { 
    184                                           if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then  
    185                                               string($DataCuratorRoleHolder/moles:name/moles:familyName) 
    186                                     else string($DataCuratorRoleHolder/moles:name) 
    187                                     }, 
    188                                 if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then  
    189                                     element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)} 
    190                                 else  
    191                                     if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then  
    192                                             (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}) 
    193                                         else (), 
    194                                 if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then  
    195                                     element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)} 
    196                                 else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then  
    197                                             element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)} 
    198                                  else (), 
    199                                 if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then  
    200                                     element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)} 
    201                                 else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then  
    202                                             element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)} 
    203                                         else (), 
    204                                 if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then  
    205                                     element Contact_Address { 
    206                                         for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline 
    207                                             return element Address {data($addressline)}, 
    208                                                         if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then  
    209                                         element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)} 
    210                                     else (), 
    211                                     if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then  
    212                                         element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)} 
    213                                     else (), 
    214                                      if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then  
    215                                          element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)} 
    216                                      else () 
    217                                      } 
    218                                 else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then  
    219                                     element Contact_Address { 
    220                                         for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline 
    221                                             return element Address {data($addressline)}, 
    222                                                             if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then  
    223                                             element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)} 
    224                                         else (), 
    225                                         if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then  
    226                                             element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)} 
    227                                         else (), 
    228                                          if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then  
    229                                              element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)} 
    230                                          else () 
    231                                      } 
    232                                 else () 
    233                                  } 
    234                         }, 
     155        for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder 
     156        [not(exists(moles:endDate)) or moles:endDate='']  
     157        return  
     158        for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
     159        [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     160        and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier 
     161        and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)] 
     162        return  
     163        element Data_Center { 
     164        element Data_Center_Name { 
     165        element Short_Name { 
     166        if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     167        string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     168        else  
     169        string($DataCuratorRoleHolder/moles:abbreviation) 
     170        }, 
     171        element Long_Name { 
     172        if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     173        string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     174        else string($DataCuratorRoleHolder/moles:name) 
     175        } 
     176        }, 
     177        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then  
     178        element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)} 
     179        else (), 
     180        for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID 
     181        return  
     182        element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, $utillib:moles_id_separator, $DGID/moles:schemeIdentifier, $utillib:moles_id_separator, $DGID/moles:localIdentifier)}, 
     183        element  Personnel { 
     184        element Role {'Data Center Contact'}, 
     185        if (exists($DataCuratorRoleHolder/name/knownAs)) then  
     186        element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)} 
     187        else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     188        element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)} 
     189        else (),                                         
     190        element Last_Name { 
     191        if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then  
     192        string($DataCuratorRoleHolder/moles:name/moles:familyName) 
     193        else string($DataCuratorRoleHolder/moles:name) 
     194        }, 
     195        if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then  
     196        element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)} 
     197        else  
     198        if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then  
     199        (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}) 
     200        else (), 
     201        if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then  
     202        element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)} 
     203        else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then  
     204        element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)} 
     205        else (), 
     206        if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then  
     207        element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)} 
     208        else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then  
     209        element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)} 
     210        else (), 
     211        if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then  
     212        element Contact_Address { 
     213        for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline 
     214        return element Address {data($addressline)}, 
     215        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then  
     216        element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)} 
     217        else (), 
     218        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then  
     219        element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)} 
     220        else (), 
     221        if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then  
     222        element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)} 
     223        else () 
     224        } 
     225        else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then  
     226        element Contact_Address { 
     227        for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline 
     228        return element Address {data($addressline)}, 
     229        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then  
     230        element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)} 
     231        else (), 
     232        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then  
     233        element Postal_Code {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)} 
     234        else (), 
     235        if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then  
     236        element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)} 
     237        else () 
     238        } 
     239        else () 
     240        } 
     241        }, 
    235242        element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}, 
    236243        for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
     
    285292            for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)  
    286293            return 
     294                    if (exists($RelURL_Desc/moles:dgSimpleLink)) then 
    287295                    element Related_URL { 
    288                     if (exist($RelURL_Desc/dgSimpleLink)) then 
    289                     element URL {data($RelURL_Desc/dgSimpleLink/URI)}, 
     296                    element URL {data($RelURL_Desc/moles:dgSimpleLink/URI)}, 
    290297                    element Description {concat(data($RelURL_Desc/dgSimpleLink/moles:name), ' - ', data($RelURL_Desc/dgSimpleLink/moles:notes))} 
    291                     else () 
    292                          }, 
     298                    } 
     299                    else (), 
    293300        element Metadata_Name {'[CEOS IDN DIF]'}, 
    294301        element Metadata_Version {'9.4'}, 
  • TI07-MOLES/trunk/MDIP/MDIPRelated.spp

    r2334 r2358  
    44                <File FilePath=".\Examples\Gemini_MDIP_v0.5.xml" HomeFolder="Yes"/> 
    55                <ExtMountFolder FolderName="C:\test"/> 
     6                <ExtMountFolder FolderName="C:\Documents and Settings\Kevin\backup\eXist_daily_070327_0301\db\discovery"/> 
    67        </Folder> 
    78        <Folder FolderName="XSL Files" ExtStr="xsl;xslt"/> 
  • TI07-MOLES/trunk/MOLES.xpr

    r2236 r2358  
    3232        <file name="v1Schema/Schemae/ndgmetadata1.2.5.xsd"/> 
    3333        <file name="v1Schema/Schemae/ndgmetadata1.3.xsd"/> 
     34        <file name="DIF/XQuery/test.xquery"/> 
    3435        <file name="StubB/XQuery/testquery.xquery"/> 
    3536    </projectTree> 
  • TI07-MOLES/trunk/PythonCode/wsgi/ndg_xqueries.py

    r2335 r2358  
    15191519declare variable $repositoryIdentifier as xs:string {'RepositoryID'}; 
    15201520declare variable $localIdentifier as xs:string {'LocalID'}; 
    1521  
    15221521for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[ 
    1523     exists('moles:dgDataEntity')  
    1524     and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  
    1525     and moles:dgMetadataID/moles:repositoryIdentifier=$repositoryIdentifier 
    1526     and moles:dgMetadataID/moles:localIdentifier=$localIdentifier] 
    1527     return 
     1522exists('moles:dgDataEntity')  
     1523and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'  
     1524and moles:dgMetadataID/moles:repositoryIdentifier=$repositoryIdentifier 
     1525and moles:dgMetadataID/moles:localIdentifier=$localIdentifier] 
     1526return 
    15281527element DIF { 
    1529     attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'}, 
    1530     element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'DIF', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)}, 
    1531     element Entry_Title {string($DE/moles:name)}, 
    1532     element Data_Set_Citation { 
    1533             for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1] 
    1534         return  
    1535             for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    1536                    and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
    1537                    and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
    1538             return  
    1539                     element Dataset_Creator { 
    1540                 if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then  
    1541                     string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))) 
    1542                 else  
    1543                    string($DataCreatorRoleHolder/moles:abbreviation) 
    1544                     }, 
    1545         element Dataset_Title {string($DE/moles:name)} 
    1546     }, 
    1547     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) or voclib:spot-vocab($voclib:gcmd_science_valids_categories, moles:dgValidTermID/moles:ParentListID))] 
    1548     ) 
    1549         return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then  
    1550             element Parameters { 
    1551             element Category {string($StructuredKeyword/*/moles:dgValidTerm)}, 
    1552             if (exists($StructuredKeyword//moles:dgValidSubterm)  
    1553                 and $StructuredKeyword//moles:dgValidSubterm != ''  
    1554                 and $StructuredKeyword//moles:dgValidSubterm != ' ') then  
    1555             for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)] 
    1556                 where exists($Subterm/moles:dgValidSubterm) 
    1557                 order by $Subterm/moles:ListLevel 
    1558                 return  
    1559                     if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    1560                     else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    1561                     else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    1562                     else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
    1563                     else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)} 
    1564             else() 
    1565                 } 
    1566         else(), 
    1567     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)]) 
    1568     return 
    1569         element Parameters {data($StructuredKeyword/moles:dgValidTerm)}, 
    1570     for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)]) 
    1571         return  
    1572             element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)}, 
    1573     for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[ 
    1574     not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID) 
    1575     or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) 
    1576     or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) 
    1577     )]/moles:dgValidTerm) 
    1578     return element Keyword {string($Keyword)},  
    1579     for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)   
    1580     return  
    1581         element Sensor_Name { 
    1582             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)) 
    1583                 return element Short_Name {data($DepDPTAbbrev)}, 
    1584             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)) 
    1585                 return element Long_Name {data($DepDPTName)} 
    1586             }, 
    1587     for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID) 
    1588     return  
    1589         element Source_Name { 
    1590             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)) 
    1591                 return element Short_Name {data($DepObsStnAbbrev)}, 
    1592             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)) 
    1593                 return element Long_Name {data($DepObsStnName)} 
    1594             }, 
    1595     for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange) 
    1596         return  
    1597             element Temporal_Coverage 
    1598                 { 
    1599                 element Start_Date {data($TemporalRange/moles:DateRangeStart)}, 
    1600                 element End_Date {data($TemporalRange/moles:DateRangeEnd)} 
    1601                 }, 
    1602     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) 
    1603         return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},  
    1604     for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure) 
    1605         return element Data_Set_Progress {data($Data_Set_Progress)}, 
    1606     for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox) 
    1607     return  
    1608         element Spatial_Coverage { 
    1609                 element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)}, 
    1610                 element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)}, 
    1611                 element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)}, 
    1612                 element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)} 
    1613             }, 
    1614     for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)]) 
    1615         return element Location {data($Location/moles:dgValidTerm)},  
    1616     for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID) 
    1617     return  
    1618         element Project { 
    1619             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) 
    1620                 return  
    1621                     element Short_Name {data($DepActAbbrev)}, 
    1622             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) 
    1623                 return  
    1624                     element Long_Name {data($DepActName)} 
    1625             }, 
    1626     if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then  
    1627             for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
    1628                 return  
    1629                                 element Access_Constraints { 
    1630                             if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then  
    1631                                 concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ') 
    1632                             else (), 
    1633                             if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then 
    1634                                 concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true())) 
    1635                             else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then 
    1636                                 data($DG/moles:accessControlPolicy/moles:accessControlPolicyText) 
    1637                              else  
    1638                                  for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition 
    1639                                  return 
    1640                                      if (exists($securityCondition/moles:conditionExplanationText)) then 
    1641                                          concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText)) 
    1642                                      else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority)) 
    1643                         } 
    1644                 else (), 
    1645     if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then 
    1646         for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder  
    1647             order by $DataCreatorRole/moles:startDate empty least 
    1648                         return  
    1649                     for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
    1650                                         [(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    1651                                         and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:repositoryIdentifier 
    1652                                         and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/(moles:dgOrganisationID | moles:dgPersonID)/moles:localIdentifier)] 
    1653                     return  
    1654                             element Originating_Center { 
    1655                     if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then 
    1656                         (string($DataCreatorRoleHolder/moles:name)) 
    1657                     else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then 
    1658                         (string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))) 
    1659                     else ('empty content') 
    1660                 } 
    1661     else (), 
    1662     for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''] 
    1663         return  
    1664             for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
    1665                and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier 
    1666                and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)] 
    1667                 return  
    1668                     element Data_Center { 
    1669                 element Data_Center_Name { 
    1670                         element Short_Name { 
    1671                             if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    1672                         string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
    1673                    else  
    1674                        string($DataCuratorRoleHolder/moles:abbreviation) 
    1675                 }, 
    1676             element Long_Name { 
    1677                     if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    1678                         string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
    1679                     else string($DataCuratorRoleHolder/moles:name) 
    1680                 } 
    1681             }, 
    1682             if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then  
    1683                     element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)} 
    1684             else (), 
    1685             for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID 
    1686             return  
    1687                 element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, '__', $DGID/moles:schemeIdentifier, '__', $DGID/moles:localIdentifier)}, 
    1688             element  Personnel { 
    1689                     element Role {'Data Center Contact'}, 
    1690                     if (exists($DataCuratorRoleHolder/name/knownAs)) then  
    1691                         element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)} 
    1692                     else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
    1693                         element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)} 
    1694                      else (),                     
    1695                      element Last_Name { 
    1696                               if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then  
    1697                                   string($DataCuratorRoleHolder/moles:name/moles:familyName) 
    1698                     else string($DataCuratorRoleHolder/moles:name) 
    1699                         }, 
    1700                     if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then  
    1701                         element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)} 
    1702                     else  
    1703                         if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then  
    1704                                 (element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}) 
    1705                                else (), 
    1706                     if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then  
    1707                         element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)} 
    1708                     else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then  
    1709                                 element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)} 
    1710                      else (), 
    1711                     if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then  
    1712                         element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)} 
    1713                     else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then  
    1714                                 element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)} 
    1715                             else (), 
    1716                     if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then  
    1717                         element Contact_Address { 
    1718                             for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline 
    1719                                 return element Address {data($addressline)}, 
    1720                                                         if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then  
    1721                             element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)} 
    1722                         else (), 
    1723                         if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then  
    1724                             element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)} 
    1725                         else (), 
    1726                          if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then  
    1727                              element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)} 
    1728                          else () 
    1729                          } 
    1730                     else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then  
    1731                         element Contact_Address { 
    1732                             for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline 
    1733                                 return element Address {data($addressline)}, 
    1734                                                             if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then  
    1735                                 element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)} 
    1736                             else (), 
    1737                             if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then  
    1738                                 element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:postcode)} 
    1739                             else (), 
    1740                              if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then  
    1741                                  element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)} 
    1742                              else () 
    1743                          } 
    1744                     else () 
    1745                      } 
    1746                         }, 
    1747     element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}, 
    1748     for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
    1749         return 
    1750             if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then  
    1751                        (element Related_URL { 
    1752                                element URL_Content_Type {'NDG_A_SERVICE'}, 
    1753                                if (exists($DG/instance/URI)) then 
    1754                                    element URL {escape-uri($DG/instance/URI, true())} 
    1755                                else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
    1756                                    element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())} 
    1757                                else ($DG/moles:dataModelID/moles:repositoryIdentifier), 
    1758                              element Description {'The NDG service delivering data via NDG A metadata.'} 
    1759                            }, 
    1760                       element Related_URL { 
    1761                                element URL_Content_Type {'GET DATA > CSML'}, 
    1762                                if (exists($DG/instance)) then 
    1763                                    element URL {escape-uri($DG/instance/URI, true())} 
    1764                                else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
    1765                                    element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())} 
    1766                                else (), 
    1767                              element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'} 
    1768                            }) 
    1769             else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then  
    1770                            (element Related_URL {  
    1771                                    element URL_Content_Type {'NDG_A_SERVICE'}, 
    1772                                if (exists($DG/instance)) then 
    1773                                    element URL {escape-uri($DG/instance/URI, true())} 
    1774                                else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
    1775                                    element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
    1776                                else (), 
    1777                              element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
    1778                                }, 
    1779                            element Related_URL { 
    1780                                element URL_Content_Type {'GET DATA > DX'}, 
    1781                                if (exists($DG/instance)) then 
    1782                                    element URL {escape-uri($DG/instance/URI, true())} 
    1783                                else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
    1784                                    element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
    1785                                else (), 
    1786                              element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
    1787                                }) 
    1788             else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then  
    1789                        element Related_URL { 
    1790                              element URL {data($DG/moles:instance/moles:URI)}, 
    1791                              if (exists($DG/moles:instance/moles:instanceComment)) then  
    1792                                      element Description {data($DG/moles:instance/moles:instanceComment)}            
    1793                              else  
    1794                                      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.'} 
    1795                           } 
    1796         else (), 
    1797         for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)  
    1798         return 
    1799                        element Related_URL { 
    1800                        if (exists($RelURL_Desc/dgSimpleLink)) then ( 
    1801                        element URL {data($RelURL_Desc/dgSimpleLink/URI)}, 
    1802                        element Description {concat(data($RelURL_Desc/dgSimpleLink/moles:name), ' - ', data($RelURL_Desc/dgSimpleLink/moles:notes))} 
    1803                        ) 
    1804                        else () 
    1805                        }, 
    1806     element Metadata_Name {'[CEOS IDN DIF]'}, 
    1807     element Metadata_Version {'9.4'}, 
    1808     if  (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then  
    1809             element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)} 
    1810     else (), 
    1811     for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate 
    1812     return   
    1813         element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))}, 
    1814     if  (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then  
    1815             element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)} 
    1816     else () 
    1817         }''' 
     1528attribute xsi:schemaLocation {'http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/ http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/dif_v9.4.xsd'}, 
     1529element Entry_ID {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'DIF', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)}, 
     1530element Entry_Title {string($DE/moles:name)}, 
     1531element Data_Set_Citation { 
     1532for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate=''][1] 
     1533return  
     1534for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/*[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1535and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
     1536and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
     1537return  
     1538element Dataset_Creator { 
     1539if (exists($DataCreatorRoleHolder/moles:name/moles:initials)) then  
     1540string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName))) 
     1541else  
     1542string($DataCreatorRoleHolder/moles:abbreviation) 
     1543}, 
     1544element Dataset_Title {string($DE/moles:name)} 
     1545}, 
     1546for $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) or voclib:spot-vocab($voclib:gcmd_science_valids_categories, moles:dgValidTermID/moles:ParentListID))] 
     1547) 
     1548return if (exists($StructuredKeyword/*/moles:dgValidTerm)) then  
     1549element Parameters { 
     1550element Category {string($StructuredKeyword/*/moles:dgValidTerm)}, 
     1551if (exists($StructuredKeyword//moles:dgValidSubterm)  
     1552and $StructuredKeyword//moles:dgValidSubterm != ''  
     1553and $StructuredKeyword//moles:dgValidSubterm != ' ') then  
     1554for $Subterm in $StructuredKeyword//moles:dgValidSubterm[exists(moles:dgValidTerm)] 
     1555where exists($Subterm/moles:dgValidSubterm) 
     1556order by $Subterm/moles:ListLevel 
     1557return  
     1558if ($Subterm/moles:ListLevel=1) then element Topic {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1559else if ($Subterm/moles:ListLevel=2) then element Term {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1560else if ($Subterm/moles:ListLevel=3) then element Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1561else if ($Subterm/moles:ListLevel=4) then element Detailed_Variable {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)}  
     1562else element GCMD_Science_Valid {string($Subterm/moles:dgValidSubterm/moles:dgValidTerm)} 
     1563else() 
     1564} 
     1565else(), 
     1566for $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)]) 
     1567return 
     1568element Parameters {data($StructuredKeyword/moles:dgValidTerm)}, 
     1569for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID)]) 
     1570return  
     1571element ISO_Topic_Category {string($ISOTopicCategory/moles:dgValidTerm)}, 
     1572for $Keyword in distinct-values($DE//moles:dgStructuredKeyword[ 
     1573not (voclib:spot-vocab($voclib:iso_topic_list, moles:dgValidTermID/moles:ParentListID) 
     1574or voclib:spot-vocab($voclib:gcmd_science_valids, moles:dgValidTermID/moles:ParentListID) 
     1575or voclib:spot-vocab($voclib:gcmd_science_valids_correct, moles:dgValidTermID/moles:ParentListID) 
     1576)]/moles:dgValidTerm) 
     1577return element Keyword {string($Keyword)},  
     1578for $DepDPT in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:DataProductionToolID)  
     1579return  
     1580element Sensor_Name { 
     1581for $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)) 
     1582return element Short_Name {data($DepDPTAbbrev)}, 
     1583for $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)) 
     1584return element Long_Name {data($DepDPTName)} 
     1585}, 
     1586for $DepObsStn in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ObservationStationID) 
     1587return  
     1588element Source_Name { 
     1589for $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)) 
     1590return element Short_Name {data($DepObsStnAbbrev)}, 
     1591for $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)) 
     1592return element Long_Name {data($DepObsStnName)} 
     1593}, 
     1594for $TemporalRange in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgDateRange) 
     1595return  
     1596element Temporal_Coverage 
     1597{ 
     1598element Start_Date {data($TemporalRange/moles:DateRangeStart)}, 
     1599element End_Date {data($TemporalRange/moles:DateRangeEnd)} 
     1600}, 
     1601for $TemporalTerm in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_chronostratigraphic_valids, moles:dgValidTermID/moles:ParentListID)]/moles:dgValidTerm) 
     1602return element Paleo_Temporal_Coverage {element Chronostratigraphic_Unit {data($TemporalTerm)}},  
     1603for $Data_Set_Progress in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataStatus/moles:dgDatasetClosure) 
     1604return element Data_Set_Progress {data($Data_Set_Progress)}, 
     1605for $BoundingBox in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox) 
     1606return  
     1607element Spatial_Coverage { 
     1608element Southernmost_Latitude {data($BoundingBox/moles:LimitSouth)}, 
     1609element Northernmost_Latitude {data($BoundingBox/moles:LimitNorth)}, 
     1610element Westernmost_Longitude {data($BoundingBox/moles:LimitWest)}, 
     1611element Easternmost_Longitude {data($BoundingBox/moles:LimitEast)} 
     1612}, 
     1613for $Location in ($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea[voclib:spot-vocab($voclib:gcmd_location_valids, moles:dgValidTermID/moles:ParentListID)]) 
     1614return element Location {data($Location/moles:dgValidTerm)},  
     1615for $DepAct in ($DE/moles:dgDataEntity/moles:RelatedDeployment/moles:ActivityID) 
     1616return  
     1617element Project { 
     1618for $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) 
     1619return  
     1620element Short_Name {data($DepActAbbrev)}, 
     1621for $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) 
     1622return  
     1623element Long_Name {data($DepActName)} 
     1624}, 
     1625if (exists($DE/moles:dgDataEntity/moles:dgDataGranule/moles:accessControlPolicy)) then  
     1626for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
     1627return  
     1628element Access_Constraints { 
     1629if (exists($DG/moles:dgGranuleSummary/moles:dgGranuleName)) then  
     1630concat('For data granule ', $DG/moles:dgGranuleSummary/moles:dgGranuleName, ': ') 
     1631else (), 
     1632if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyURL)) then 
     1633concat('See access control policy at ', escape-uri($DG/moles:accessControlPolicy/moles:accessControlPolicyURL, true())) 
     1634else if (exists($DG/moles:accessControlPolicy/moles:accessControlPolicyText)) then 
     1635data($DG/moles:accessControlPolicy/moles:accessControlPolicyText) 
     1636else  
     1637for $securityCondition in $DG/moles:accessControlPolicy/moles:dgSecurityCondition 
     1638return 
     1639if (exists($securityCondition/moles:conditionExplanationText)) then 
     1640concat('Effect: ', data($securityCondition/moles:effect), ' - ', data($securityCondition/moles:conditionExplanationText)) 
     1641else concat('Effect: ', data($securityCondition/moles:effect), 'needs ', data($securityCondition/moles:attauthRole), ' from ', data($securityCondition/moles:dgAttributeAuthority)) 
     1642} 
     1643else (), 
     1644if (exists($DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder)) then 
     1645for $DataCreatorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCreator/moles:dgRoleHolder  
     1646order by $DataCreatorRole/moles:startDate empty least 
     1647return  
     1648for $DataCreatorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
     1649[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1650and moles:dgMetadataID/moles:repositoryIdentifier=$DataCreatorRole/*/moles:repositoryIdentifier 
     1651and moles:dgMetadataID/moles:localIdentifier=$DataCreatorRole/*/moles:localIdentifier)] 
     1652return  
     1653element Originating_Center { 
     1654if (string(local-name($DataCreatorRoleHolder))='dgOrganisation') then 
     1655(string($DataCreatorRoleHolder/moles:name)) 
     1656else if (string(local-name($DataCreatorRoleHolder))='dgPerson') then 
     1657(string(concat(string($DataCreatorRoleHolder/moles:name/moles:initials), ' ', string($DataCreatorRoleHolder/moles:name/moles:familyName)))) 
     1658else ('empty content') 
     1659} 
     1660else (), 
     1661for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder 
     1662[not(exists(moles:endDate)) or moles:endDate='']  
     1663return  
     1664for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgOrganisation | moles:dgPerson) 
     1665[(moles:dgMetadataID/moles:schemeIdentifier='NDG-B0' 
     1666and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/*/moles:repositoryIdentifier 
     1667and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/*/moles:localIdentifier)] 
     1668return  
     1669element Data_Center { 
     1670element Data_Center_Name { 
     1671element Short_Name { 
     1672if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1673string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     1674else  
     1675string($DataCuratorRoleHolder/moles:abbreviation) 
     1676}, 
     1677element Long_Name { 
     1678if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1679string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName))) 
     1680else string($DataCuratorRoleHolder/moles:name) 
     1681} 
     1682}, 
     1683if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:URI)) then  
     1684element Data_Center_URL {data($DataCuratorRoleHolder/moles:contactDetails/moles:URI)} 
     1685else (), 
     1686for $DGID in $DE/moles:dgDataEntity/moles:dgDataGranule/moles:dataModelID 
     1687return  
     1688element Data_Set_ID {concat($DGID/moles:repositoryIdentifier, $utillib:moles_id_separator, $DGID/moles:schemeIdentifier, $utillib:moles_id_separator, $DGID/moles:localIdentifier)}, 
     1689element Personnel { 
     1690element Role {'Data Center Contact'}, 
     1691if (exists($DataCuratorRoleHolder/name/knownAs)) then  
     1692element First_Name {string($DataCuratorRoleHolder/moles:name/moles:knownAs)} 
     1693else if (exists($DataCuratorRoleHolder/moles:name/moles:initials)) then  
     1694element First_Name {string($DataCuratorRoleHolder/moles:name/moles:initials)} 
     1695else (), 
     1696element Last_Name { 
     1697if (exists($DataCuratorRoleHolder/moles:name/moles:familyName)) then  
     1698string($DataCuratorRoleHolder/moles:name/moles:familyName) 
     1699else string($DataCuratorRoleHolder/moles:name) 
     1700}, 
     1701if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then  
     1702element Email {string($DataCuratorRole/moles:contactDetails/moles:eMail)} 
     1703else  
     1704if (exists($DataCuratorRoleHolder/contactDetails/eMail)) then  
     1705(element Email {string($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}) 
     1706else (), 
     1707if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then  
     1708element Phone {string($DataCuratorRole/moles:contactDetails/moles:telephone)} 
     1709else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then  
     1710element Phone {string($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)} 
     1711else (), 
     1712if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then  
     1713element Fax {string($DataCuratorRole/moles:contactDetails/moles:fax)} 
     1714else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then  
     1715element Fax {string($DataCuratorRoleHolder/moles:contactDetails/moles:fax)} 
     1716else (), 
     1717if (exists($DataCuratorRole/moles:contactDetails/moles:address)) then  
     1718element Contact_Address { 
     1719for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline 
     1720return element Address {data($addressline)}, 
     1721if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then  
     1722element City {string($DataCuratorRole/moles:contactDetails/moles:address/moles:city)} 
     1723else (), 
     1724if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)) then  
     1725element Postal_Code {string($DataCuratorRole/moles:contactDetails/moles:address/moles:postcode)} 
     1726else (), 
     1727if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:country)) then  
     1728element Country {string($DataCuratorRole/moles:contactDetails/moles:address/moles:country)} 
     1729else () 
     1730} 
     1731else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address)) then  
     1732element Contact_Address { 
     1733for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline 
     1734return element Address {data($addressline)}, 
     1735if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then  
     1736element City {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)} 
     1737else (), 
     1738if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then  
     1739element Postal_Code {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)} 
     1740else (), 
     1741if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)) then  
     1742element Country {string($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:country)} 
     1743else () 
     1744} 
     1745else () 
     1746} 
     1747}, 
     1748element Summary {string($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}, 
     1749for $DG in $DE/moles:dgDataEntity/moles:dgDataGranule 
     1750return 
     1751if ($DG/moles:dataModelID/moles:schemeIdentifier='NDG-A0') then  
     1752(element Related_URL { 
     1753element URL_Content_Type {'NDG_A_SERVICE'}, 
     1754if (exists($DG/instance/URI)) then 
     1755element URL {escape-uri($DG/instance/URI, true())} 
     1756else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1757element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())} 
     1758else ($DG/moles:dataModelID/moles:repositoryIdentifier), 
     1759element Description {'The NDG service delivering data via NDG A metadata.'} 
     1760}, 
     1761element Related_URL { 
     1762element URL_Content_Type {'GET DATA > CSML'}, 
     1763if (exists($DG/instance)) then 
     1764element URL {escape-uri($DG/instance/URI, true())} 
     1765else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1766element URL {escape-uri('http://dmgdev1.esc.rl.ac.uk/cgi-bin/ndgDataAccess?datasetSource=dmgdev1.esc.rl.ac.uk&amp;datasetID=', true())} 
     1767else (), 
     1768element Description {'The NDG service delivering data via NDG A metadata. Additional tag to be more in line with latest version of GCMD valids'} 
     1769}) 
     1770else if ($DG/moles:dataModelID/moles:schemeIdentifier='CDML-0') then  
     1771(element Related_URL {  
     1772element URL_Content_Type {'NDG_A_SERVICE'}, 
     1773if (exists($DG/instance)) then 
     1774element URL {escape-uri($DG/instance/URI, true())} 
     1775else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1776element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
     1777else (), 
     1778element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
     1779}, 
     1780element Related_URL { 
     1781element URL_Content_Type {'GET DATA > DX'}, 
     1782if (exists($DG/instance)) then 
     1783element URL {escape-uri($DG/instance/URI, true())} 
     1784else if ($DG/moles:dataModelID/moles:repositoryIdentifier='badc.nerc.ac.uk') then 
     1785element URL {escape-uri('http://cdat.badc.nerc.ac.uk/cgi-bin/dxui.py?datasetURI_1=/', true())} 
     1786else (), 
     1787element Description {'The NDG service delivering data via Data extractor. Additional tag to be more in line with latest version of GCMD valids'} 
     1788}) 
     1789else if ($DG/moles:dataModelID/moles:schemeIdentifier='URI') then  
     1790element Related_URL { 
     1791element URL {data($DG/moles:instance/moles:URI)}, 
     1792if (exists($DG/moles:instance/moles:instanceComment)) then  
     1793element Description {data($DG/moles:instance/moles:instanceComment)} 
     1794else  
     1795element 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.'} 
     1796} 
     1797else (), 
     1798for $RelURL_Desc in ($DE/moles:dgMetadataDescription/moles:descriptionSection/moles:descriptionOnlineReference)  
     1799return 
     1800if (exists($RelURL_Desc/moles:dgSimpleLink)) then 
     1801element Related_URL { 
     1802element URL {data($RelURL_Desc/moles:dgSimpleLink/URI)}, 
     1803element Description {concat(data($RelURL_Desc/dgSimpleLink/moles:name), ' - ', data($RelURL_Desc/dgSimpleLink/moles:notes))} 
     1804} 
     1805else (), 
     1806element Metadata_Name {'[CEOS IDN DIF]'}, 
     1807element Metadata_Version {'9.4'}, 
     1808if (exists($DE/moles:dgMetadataProvenance/moles:RecordCreation)) then  
     1809element DIF_Creation_Date {data($DE/moles:dgMetadataProvenance/moles:RecordCreation/moles:CreatedDate)} 
     1810else (), 
     1811for $MDUpdt in $DE/moles:dgMetadataProvenance/moles:RecordUpdate 
     1812return  
     1813element DIF_Revision_History {concat(data($MDUpdt/moles:UpdateDate), ' - ', data($MDUpdt/moles:UpdateSummary), ' - ', data($MDUpdt/moles:UpdatedBy))}, 
     1814if (exists($DE/moles:dgMetadataProvenance/moles:RecordReview)) then  
     1815element Future_DIF_Review_Date {data($DE/moles:dgMetadataProvenance/moles:RecordReview/moles:ReviewDate)} 
     1816else () 
     1817}''' 
    18181818         
    18191819DublinCoreDEQuery='''import module namespace voclib='http://ndg.nerc.ac.uk/xquery/lib/vocab' at 'xmldb:exist:///db/xqueryLib/Vocabs/vocab_xquery_lib.xquery'; 
Note: See TracChangeset for help on using the changeset viewer.