source: exist/trunk/xquery/moles2iso19139.xq @ 3841

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/exist/trunk/xquery/moles2iso19139.xq@4326
Revision 3841, 10.5 KB checked in by cbyrom, 12 years ago (diff)

Various updates to the xquery files - to remove usage of invalid specs
and dependency on obsolete function calls. Also add the inputParse_xquery_lib.xquery
file - referenced from the xquery files but not currently included in codebase.
NB, changes made to allow use of Saxon java library to do xqueries - to
remove the need for the discovery service eXist DB.

  • NB, also changes tested by comparing saxon transforms to eXist ones; these

were found to be identical.

Line 
1(: This xquery for TargetCollection RepositoryID and LocalID will find and convert Moles to ISO19139 :)
2import module namespace utillib='http://ndg.nerc.ac.uk/xquery/lib/utilities' at 'xmldb:exist:///db/xqueryLib/Utilities/utility_xquery_lib.xquery';
3
4declare default element namespace 'http://www.isotc211.org/2005/gmd';
5declare namespace moles='http://ndg.nerc.ac.uk/moles';
6declare namespace gco='http://www.isotc211.org/2005/gco';
7declare namespace gmd='http://www.isotc211.org/2005/gmd';
8declare namespace gml='http://www.opengis.net/gml';
9declare namespace xlink='http://www.w3.org/1999/xlink';
10declare namespace xsi='http://www.w3.org/2001/XMLSchema-instance';
11(:
12This option doesn't work when using with saxon - as used by the ingest
13declare option exist:timeout '24500';
14:)
15
16declare variable $targetCollection as xs:string := 'TargetCollection';
17declare variable $repositoryIdentifier as xs:string := 'RepositoryID';
18declare variable $localIdentifier as xs:string := 'LocalID';
19
20for $DE in collection($targetCollection)/moles:dgMetadata/moles:dgMetadataRecord[
21exists(moles:dgDataEntity)
22and moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
23and moles:dgMetadataID/moles:localIdentifier=$localIdentifier]
24return
25element MD_Metadata {
26attribute xsi:schemaLocation {'http://www.isotc211.org/2005/gmd http://www.isotc211.org/2005/gmd/metadataEntity.xsd'},
27element fileIdentifier {element gco:CharacterString {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, $utillib:moles_id_separator, 'ISO19115', $utillib:moles_id_separator, $DE/moles:dgMetadataID/moles:localIdentifier)}},
28element language {
29element gmd:LanguageCode {
30attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCode'},
31attribute codeListValue {'eng'},
32'English'}
33} (: </language> :),
34element hierarchyLevel {
35element MD_ScopeCode {
36attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode'},
37attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_ScopeCode_dataset'},
38'dataset'}
39} (: </hierarchyLevel> :),
40for $parent in $DE/moles:dgRelatedDataEntity[moles:RelationID/moles:dgValidTerm='is-part-of']
41return
42element parentIdentifier  {element gco:CharacterString {concat($DE/moles:dgMetadataID/moles:repositoryIdentifier, ':', $DE/moles:dgMetadataID/moles:localIdentifier, ':', $DE/moles:dgMetadataID/moles:localIdentifier)}},
43for $DataCuratorRole in $DE/moles:dgDataEntity/moles:dgDataRoles/moles:dgDataCurator/moles:dgRoleHolder[not(exists(moles:endDate)) or moles:endDate='']
44return
45for $DataCuratorRoleHolder in collection($targetCollection)/moles:dgMetadata/(moles:dgPerson | moles:dgOrganisation)[
46moles:dgMetadataID/moles:schemeIdentifier='NDG-B0'
47and moles:dgMetadataID/moles:repositoryIdentifier=$DataCuratorRole/(moles:dgPersonID | moles:dgOrganisationID)/moles:repositoryIdentifier
48and moles:dgMetadataID/moles:localIdentifier=$DataCuratorRole/(moles:dgPersonID | moles:dgOrganisationID)/moles:localIdentifier]
49return
50element contact {
51element CI_ResponsibleParty {
52if (string(local-name($DataCuratorRoleHolder))='dgOrganisation') then
53element organisationName {element gco:CharacterString {string($DataCuratorRoleHolder/moles:name)}}
54else if (string(local-name($DataCuratorRoleHolder))='dgPerson') then
55element individualName {element gco:CharacterString {string(concat(string($DataCuratorRoleHolder/moles:name/moles:initials), ' ', string($DataCuratorRoleHolder/moles:name/moles:familyName)))}}
56else ('empty content') ,     
57element positionName {
58if (exists($DataCuratorRoleHolder/moles:localName)) then
59element gco:CharacterString {$DataCuratorRoleHolder/moles:localName}
60else if (exists($DataCuratorRole/moles:roleName)) then
61element gco:CharacterString {$DataCuratorRole/moles:roleName}
62else
63element gco:CharacterString {'Curator'}
64} (: </positionName>:),
65element contactInfo {
66element gmd:CI_Contact {
67if (exists($DataCuratorRole/moles:contactDetails/moles:telephone
68or $DataCuratorRole/moles:contactDetails/moles:fax
69or $DataCuratorRoleHolder/moles:contactDetails/moles:telephone
70or $DataCuratorRoleHolder/moles:contactDetails/moles:fax)) then
71element phone {
72element gmd:CI_Telephone {
73if (exists($DataCuratorRole/moles:contactDetails/moles:telephone)) then
74element voice {
75element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:telephone)}
76} (:</voice>:)
77else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then
78element voice {
79element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)}
80} (:</voice>:)
81else (),
82if (exists($DataCuratorRole/moles:contactDetails/moles:fax)) then
83element facsimile {
84element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}
85} (: </facsimile> :)
86else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:telephone)) then
87element facsimile {
88element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:fax)}
89} (: </facsimile> :)
90else ()
91} (: </gmd:CI_Telephone> :)
92} (: </phone> :)
93else (),
94element address {
95element gmd:CI_Address {
96if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:addressline)) then                               
97for $addressline in $DataCuratorRole/moles:contactDetails/moles:address/moles:addressline
98return
99element deliveryPoint {element gco:CharacterString {data($addressline)}}
100else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline)) then
101for $addressline in $DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:addressline
102return
103element deliveryPoint {element gco:CharacterString {data($addressline)}}
104else (),
105if (exists($DataCuratorRole/moles:contactDetails/moles:address/moles:city)) then
106element city {element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:address/moles:city)}}
107else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)) then
108element city {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:city)}}
109else (),
110if (exists($DataCuratorRole/moles:contactDetails/moles:eMail)) then
111element electronicMailAddress {element gco:CharacterString {data($DataCuratorRole/moles:contactDetails/moles:eMail)}}
112else if (exists($DataCuratorRoleHolder/moles:contactDetails/moles:address/moles:postcode)) then
113element electronicMailAddress {element gco:CharacterString {data($DataCuratorRoleHolder/moles:contactDetails/moles:eMail)}}
114else ()
115} (: </gmd:CI_Address> :)
116} (: </address> :)
117} (: </gmd:CI_Contact> :)
118} (: </contactInfo> :),
119element role {
120element CI_RoleCode {
121attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode'},
122attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_RoleCode_custodian'},
123if (exists($DataCuratorRole/moles:localName)) then                               
124data($DataCuratorRole/moles:localName)
125else if (exists($DataCuratorRoleHolder/moles:localName)) then
126data($DataCuratorRoleHolder/moles:localName)
127else 'Curator' 
128} (: </CI_RoleCode> :)
129} (: </role> :)
130} (: </CI_ResponsibleParty> :)
131} (: </contact> :),
132
133element dateStamp {element gco:Date {adjust-date-to-timezone(current-date())}},
134element metadataStandardName {element gco:CharacterString {'ISO 19115:2003'}},
135element metadataStandardVersion {element gco:CharacterString {'2003'}},
136element identificationInfo {
137element gmd:MD_DataIdentification {
138element citation {
139element gmd:CI_Citation {
140element title {element gco:CharacterString {data($DE/moles:name)}},
141if (exists($DE/moles:abbreviation) and not(empty($DE/moles:abbreviation))) then
142element alternateTitle {element gco:CharacterString {data($DE/moles:abbreviation)}}
143else (),
144element date {
145if (exists($DE/(moles:DataProvenance | moles:dgMetadataProvenance)/moles:RecordCreation/moles:CreatedDate)) then
146element gmd:CI_Date {
147element date {element gco:Date {adjust-date-to-timezone(data($DE/(moles:DataProvenance | moles:dgMetadataProvenance)/moles:RecordCreation/moles:CreatedDate))}},
148element dateType {
149element CI_DateTypeCode {
150attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode'},
151attribute codeListValue {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#CI_DateTypeCode_creation' },
152'Creation'}
153} (: </dataType> :)
154} (: </gmd:CI_Date> :)
155else
156attribute gco:nilReason {'unknown'}
157} (: </date> :)
158} (: </gmd:CI_Citation> :)
159} (: </citation> :),
160element abstract {element gco:CharacterString {data($DE/moles:dgMetadataDescription/moles:abstract/moles:abstractText)}},
161element language {
162element gmd:LanguageCode {
163attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#LanguageCode'},
164attribute codeListValue {'eng'},
165'English' }
166} (: </language> :),
167for $ISOTopicCategory in ($DE/moles:dgStructuredKeyword[dgValidTermID/moles:ParentListID='http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'])
168return
169element topicCategory {
170element gmd:MD_TopicCategoryCode {
171attribute codeList {'http://www.isotc211.org/2005/resources/Codelist/gmxCodelists.xml#MD_TopicCategoryCode'},
172attribute codeListValue {string($ISOTopicCategory/moles:dgValidTerm)},
173string($ISOTopicCategory/moles:dgValidTerm)}
174} (: </topicCategory> :),
175if (exists($DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage)) then
176element extent {
177element gmd:EX_Extent {
178(: add bounding boxes:)
179for $geoBBox in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:BoundingBox
180return
181element geographicElement {
182element EX_GeographicBoundingBox {
183element westBoundLongitude {element gco:Decimal {data($geoBBox/moles:LimitWest)}},
184element eastBoundLongitude {element gco:Decimal {data($geoBBox/moles:LimitEast)}},
185element southBoundLatitude {element gco:Decimal {data($geoBBox/moles:LimitSouth)}},
186element northBoundLatitude {element gco:Decimal {data($geoBBox/moles:LimitNorth)}}
187} (: </EX_GeographicBoundingBox> :)
188} (: </geographicElement> :),
189(: add location terms:)
190for $geoArea in $DE/moles:dgDataEntity/moles:dgDataSummary/moles:dgDataCoverage//moles:dgArea
191return
192element geographicElement {
193element EX_GeographicDescription {
194element geographicIdentifier {
195element gmd:RS_Identifier {
196element gco:CharacterString {element code {data($geoArea/moles:dgValidTerm)}},
197element gco:CharacterString {element codeSpace {data($geoArea/moles:dgValidTermID/moles:ParentListID)}}
198}
199}
200} (: </EX_GeographicDescription> :)
201} (: </geographicElement> :)
202} (: </gmd:EX_Extent> :)
203} (: </extent> :)
204else()
205} (:</gmd:MD_DataIdentification> :)
206} (: </identificationInfo> :)
207} (: </MD_Metadata> :)
Note: See TracBrowser for help on using the repository browser.