Skip to content

Commit

Permalink
Merge pull request #16 from ianwallen/main.prevent.delete.multiple.on…
Browse files Browse the repository at this point in the history
…line.resources.iso.19139.schema

Fix issues based on code review.
  • Loading branch information
wangf1122 authored Jan 15, 2024
2 parents 5322776 + fba52da commit e5e6f92
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 118 deletions.
12 changes: 6 additions & 6 deletions schemas/iso19139/src/main/plugin/iso19139/extract-relations.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@
</xsl:call-template>
</xsl:variable>

<xsl:if test="count(*/descendant::*[name(.) = 'gmd:graphicOverview']/*) > 0">
<xsl:if test="count(*//gmd:graphicOverview) > 0">
<thumbnails>
<xsl:for-each select="*/descendant::*[name(.) = 'gmd:graphicOverview']">
<xsl:for-each select="*//gmd:graphicOverview">
<item>
<id>
<xsl:value-of select="gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString"/>
Expand All @@ -109,7 +109,7 @@
<xsl:value-of select="position()"/>
</idx>
<hash>
<xsl:value-of select="util:md5Hex(exslt:node-set(.))"/>
<xsl:value-of select="util:md5Hex(string(exslt:node-set(.)))"/>
</hash>
<url>
<xsl:apply-templates mode="get-iso19139-localized-string"
Expand All @@ -125,9 +125,9 @@
</thumbnails>
</xsl:if>

<xsl:if test="count(*/descendant::*[name(.) = 'gmd:onLine']/*[gmd:linkage/gmd:URL!='']) > 0">
<xsl:if test="count(*//gmd:MD_DigitalTransferOptions/gmd:onLine[gmd:CI_OnlineResource[gmd:linkage/gmd:URL!='']]) > 0">
<onlines>
<xsl:for-each select="*/descendant::*[name(.) = 'gmd:onLine']">
<xsl:for-each select="*//gmd:MD_DigitalTransferOptions/gmd:onLine">
<xsl:if test="gmd:CI_OnlineResource[gmd:linkage/gmd:URL!='']">
<item>
<xsl:variable name="langCode">
Expand All @@ -141,7 +141,7 @@
<xsl:value-of select="position()"/>
</idx>
<hash>
<xsl:value-of select="util:md5Hex(exslt:node-set(.))"/>
<xsl:value-of select="util:md5Hex(string(exslt:node-set(.)))"/>
</hash>
<title>
<xsl:apply-templates mode="get-iso19139-localized-string"
Expand Down
139 changes: 82 additions & 57 deletions schemas/iso19139/src/main/plugin/iso19139/process/onlinesrc-add.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<!--
Processing to insert or update an online resource element.
Insert is made in first transferOptions found.
Note: It assumes that it will be adding new items in
the first /gmd:distributionInfo
and first /gmd:MD_Distribution
and first /gmd:transferOptions
-->
<xsl:stylesheet xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gco="http://www.isotc211.org/2005/gco"
Expand Down Expand Up @@ -77,99 +82,119 @@ Insert is made in first transferOptions found.

<!-- Add new gmd:onLine and consider cases where parent elements don't exist -->
<!-- <gmd:distributionInfo> does not exist-->
<xsl:template match="gmd:MD_Metadata[$update_flag = false()]|*[@gco:isoType='gmd:MD_Metadata' and $update_flag = false()]">
<xsl:template match="gmd:MD_Metadata[not(gmd:distributionInfo) and $update_flag = false()]|*[@gco:isoType='gmd:MD_Metadata' and not(gmd:distributionInfo) and $update_flag = false()]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:if test="not(gmd:distributionInfo)">
<gmd:distributionInfo>
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>
</xsl:if>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates
select="gmd:fileIdentifier|
gmd:language|
gmd:characterSet|
gmd:parentIdentifier|
gmd:hierarchyLevel|
gmd:hierarchyLevelName|
gmd:contact|
gmd:dateStamp|
gmd:metadataStandardName|
gmd:metadataStandardVersion|
gmd:dataSetURI|
gmd:locale|
gmd:spatialRepresentationInfo|
gmd:referenceSystemInfo|
gmd:metadataExtensionInfo|
gmd:identificationInfo|
gmd:contentInfo"/>

<gmd:distributionInfo>
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</gmd:distributionInfo>


<xsl:apply-templates
select="gmd:dataQualityInfo|
gmd:portrayalCatalogueInfo|
gmd:metadataConstraints|
gmd:applicationSchemaInfo|
gmd:metadataMaintenance|
gmd:series|
gmd:describes|
gmd:propertyType|
gmd:featureType|
gmd:featureAttribute"/>
</xsl:copy>
</xsl:template>

<!-- <gmd:MD_Distribution> does not exist-->
<xsl:template match="*/gmd:distributionInfo[$update_flag = false()]">
<xsl:template match="*/gmd:distributionInfo[not(gmd:MD_Distribution) and $update_flag = false() and position() = 1]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:if test="not(gmd:MD_Distribution)">
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</xsl:if>
<gmd:MD_Distribution>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</gmd:MD_Distribution>
</xsl:copy>
</xsl:template>

<!-- <gmd:transferOptions> does not exist-->
<xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution[$update_flag = false()]">
<xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[not(gmd:transferOptions) and $update_flag = false() and position() = 1]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:if test="not(gmd:transferOptions)">
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</xsl:if>
<gmd:transferOptions>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</gmd:transferOptions>
</xsl:copy>
</xsl:template>

<!-- <gmd:MD_DigitalTransferOptions> does not exist-->
<xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions[$update_flag = false()][1]">
<xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[1]/gmd:transferOptions[not(gmd:MD_DigitalTransferOptions) and $update_flag = false() and position() = 1]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:if test="not(gmd:MD_DigitalTransferOptions)">
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</xsl:if>
<gmd:MD_DigitalTransferOptions>
<xsl:call-template name="createOnlineSrc"/>
</gmd:MD_DigitalTransferOptions>
</xsl:copy>
</xsl:template>

<!-- Add new gmd:gmd:onLine-->
<xsl:template match="*/gmd:distributionInfo/gmd:MD_Distribution/gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions[$update_flag = false()]">
<xsl:template match="*/gmd:distributionInfo[1]/gmd:MD_Distribution[1]/gmd:transferOptions[1]/gmd:MD_DigitalTransferOptions[$update_flag = false() and position() = 1]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates
select="gmd:unitsOfDistribution|
gmd:transferSize|
gmd:onLine"/>

<xsl:call-template name="createOnlineSrc"/>

<xsl:apply-templates select="gmd:offLine"/>
</xsl:copy>
</xsl:template>

<!-- End of inserting gmd:onLine -->


<!-- Updating the gmd:onLine based on update parameters -->
<!-- Note: first part of the match needs to match the xsl:for-each select from extract-relations.xsl in order to get the position() to match -->
<xsl:template
priority="2"
match="*[$update_flag = true() and gmd:onLine]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except gmd:onLine" />

<xsl:for-each select="gmd:onLine">
<xsl:choose>
<xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx))
and ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
match="*//gmd:MD_DigitalTransferOptions/gmd:onLine
[gmd:CI_OnlineResource[gmd:linkage/gmd:URL!=''] and ($resourceIdx = '' or position() = xs:integer($resourceIdx))]
[($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
gmd:CI_OnlineResource/gmd:linkage/gmd:URL,
gmd:CI_OnlineResource/gmd:protocol/*,
gmd:CI_OnlineResource/gmd:name/gco:CharacterString)))
and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)">
<xsl:call-template name="createOnlineSrc"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"
priority="2">
<xsl:call-template name="createOnlineSrc"/>
</xsl:template>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,16 @@ Stylesheet used to remove a reference to a online resource.
<xsl:param name="name" select="''"/>

<!-- Remove the gmd:onLine define in url parameter -->
<!-- Note: first part of the match needs to match the xsl:for-each select from extract-relations.xsl in order to get the position() to match -->
<xsl:template
priority="2"
match="*[gmd:onLine]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except gmd:onLine" />

<xsl:for-each select="gmd:onLine">
<xsl:choose>
<xsl:when test="gmd:CI_OnlineResource[gmd:linkage/gmd:URL!='']
and ($resourceIdx = '' or position() = xs:integer($resourceIdx))
and ($resourceHash != '' or ($url != null and (normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)
match="*//gmd:MD_DigitalTransferOptions/gmd:onLine
[gmd:CI_OnlineResource[gmd:linkage/gmd:URL!=''] and ($resourceIdx = '' or position() = xs:integer($resourceIdx))]
[($resourceHash != '' or ($url != null and (normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:name/gco:CharacterString) = normalize-space($name)
or normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and count(gmd:CI_OnlineResource/gmd:name/gmd:PT_FreeText/gmd:textGroup[gmd:LocalisedCharacterString = $name]) > 0
or normalize-space(gmd:CI_OnlineResource/gmd:linkage/gmd:URL) = $url and normalize-space(gmd:CI_OnlineResource/gmd:protocol/*) = 'WWW:DOWNLOAD-1.0-http--download'))
)
and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)">
<!-- Remove the thumbnail -->
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"
priority="2"/>

<!-- Do a copy of every node and attribute -->
<xsl:template match="@*|node()">
Expand Down
54 changes: 36 additions & 18 deletions schemas/iso19139/src/main/plugin/iso19139/process/thumbnail-add.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,53 @@
<!-- Add new gmd:graphicOverview -->
<xsl:template match="gmd:identificationInfo/*[$update_flag = false()]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="gmd:citation"/>
<xsl:apply-templates select="gmd:abstract"/>
<xsl:apply-templates select="gmd:purpose"/>
<xsl:apply-templates select="gmd:credit"/>
<xsl:apply-templates select="gmd:status"/>
<xsl:apply-templates select="gmd:pointOfContact"/>
<xsl:apply-templates select="gmd:resourceMaintenance"/>

<xsl:call-template name="fill"/>

<xsl:apply-templates select="gmd:graphicOverview"/>

<xsl:apply-templates select="gmd:resourceFormat"/>
<xsl:apply-templates select="gmd:descriptiveKeywords"/>
<xsl:apply-templates select="gmd:resourceSpecificUsage"/>
<xsl:apply-templates select="gmd:resourceConstraints"/>
<xsl:apply-templates select="gmd:aggregationInfo"/>
<xsl:apply-templates select="gmd:spatialRepresentationType"/>
<xsl:apply-templates select="gmd:spatialResolution"/>
<xsl:apply-templates select="gmd:language"/>
<xsl:apply-templates select="gmd:characterSet"/>
<xsl:apply-templates select="gmd:topicCategory"/>
<xsl:apply-templates select="gmd:environmentDescription"/>
<xsl:apply-templates select="gmd:extent"/>
<xsl:apply-templates select="gmd:supplementalInformation"/>

<xsl:apply-templates select="srv:*"/>

<xsl:apply-templates select="*[namespace-uri()!='http://www.isotc211.org/2005/gmd' and
namespace-uri()!='http://www.isotc211.org/2005/srv']"/>
</xsl:copy>
</xsl:template>

<!-- Updating the gmd:graphicOverview based on update parameters -->
<!-- Note: first part of the match needs to match the xsl:for-each select from extract-relations.xsl in order to get the position() to match -->
<xsl:template
priority="2"
match="*[$update_flag = true() and gmd:graphicOverview]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except gmd:graphicOverview" />

<xsl:for-each select="gmd:graphicOverview">
<xsl:choose>
<xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx))
and ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
match="*//gmd:graphicOverview
[$resourceIdx = '' or position() = xs:integer($resourceIdx)]
[ ($resourceHash != '' or ($updateKey != '' and normalize-space($updateKey) = concat(
*/gmd:fileName/gco:CharacterString,
*/gmd:fileName/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'],
*/gmd:fileDescription/gmd:PT_FreeText/gmd:textGroup/gmd:LocalisedCharacterString[@locale = '#DE'],
*/gmd:fileDescription/gco:CharacterString)))
and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)">
<xsl:call-template name="fill"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]">
<xsl:call-template name="fill"/>
</xsl:template>

<!-- TMP TO REMOVE when gco:characterString is added in multilingual elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,13 @@
<xsl:param name="resourceIdx" select="''"/>

<!-- Remove the thumbnail define in thumbnail_url parameter -->
<!-- Note: first part of the match needs to match the xsl:for-each select from extract-relations.xsl in order to get the position() to match -->
<xsl:template
priority="4"
match="*[gmd:graphicOverview]">
<xsl:copy>
<xsl:apply-templates select="@*|node() except gmd:graphicOverview" />
<xsl:for-each select="gmd:graphicOverview">
<xsl:choose>
<xsl:when test="($resourceIdx = '' or position() = xs:integer($resourceIdx))
and ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url)))
and ($resourceHash = '' or digestUtils:md5Hex(exslt:node-set(.)) = $resourceHash)">
<!-- Remove the thumbnail -->
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:copy>
</xsl:template>
match="*//gmd:graphicOverview
[$resourceIdx = '' or position() = xs:integer($resourceIdx)]
[ ($resourceHash != '' or ($thumbnail_url != '' and normalize-space(gmd:MD_BrowseGraphic/gmd:fileName/gco:CharacterString) = normalize-space($thumbnail_url)))
and ($resourceHash = '' or digestUtils:md5Hex(string(exslt:node-set(.))) = $resourceHash)]"/>

<!-- Do a copy of every node and attribute -->
<xsl:template match="@*|node()">
Expand Down

0 comments on commit e5e6f92

Please sign in to comment.