Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor / Polygon / Fix validation error on srsName and id attributes. #4791

Merged
merged 7 commits into from
Jul 3, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</xsl:choose>
</xsl:template>


<xsl:template match="gml:LinearRing/@srsName"/>

<xsl:template name="correct_ns_prefix">
<xsl:param name="element"/>
Expand Down
129 changes: 84 additions & 45 deletions schemas/iso19139/src/main/plugin/iso19139/update-fixed-info.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@

<!-- The default language is also added as gmd:locale
for multilingual metadata records. -->
<xsl:variable name="mainLanguage">
<xsl:call-template name="langId_from_gmdlanguage19139">
<xsl:with-param name="gmdlanguage" select="/root/*/gmd:language"/>
</xsl:call-template>
<xsl:variable name="mainLanguage">
<xsl:call-template name="langId_from_gmdlanguage19139">
<xsl:with-param name="gmdlanguage" select="/root/*/gmd:language"/>
</xsl:call-template>
</xsl:variable>

<xsl:variable name="isMultilingual"
Expand Down Expand Up @@ -259,8 +259,10 @@
<xsl:template match="@gml:id|@gml320:id">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
<xsl:attribute name="{if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'}:id">
<xsl:attribute name="gml:id"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:value-of select="generate-id(.)"/>
</xsl:attribute>
</xsl:when>
Expand All @@ -274,6 +276,8 @@
<!-- Fix srsName attribute generate CRS:84 (EPSG:4326 with long/lat
ordering) by default -->

<xsl:template match="gml:LinearRing/@srsName|gml320:LinearRing/@srsName"/>

<xsl:template match="@srsName">
<xsl:choose>
<xsl:when test="normalize-space(.)=''">
Expand All @@ -287,30 +291,44 @@
</xsl:choose>
</xsl:template>


<!-- Add required gml attributes if missing -->
<xsl:template match="gml:Polygon[not(@gml:id) and not(@srsName)]|
gml:MultiSurface[not(@gml:id) and not(@srsName)]|
gml:LineString[not(@gml:id) and not(@srsName)]|
gml320:Polygon[not(@gml320:id) and not(@srsName)]">
<xsl:copy copy-namespaces="no">
<xsl:choose>
<xsl:when test="$isUsing2005Schema and not($isUsing2007Schema)">
<xsl:namespace name="gml320" select="'http://www.opengis.net/gml'"/>
</xsl:when>
<xsl:otherwise>
<xsl:namespace name="gml" select="'http://www.opengis.net/gml/3.2'"/>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="{if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'}:id">
<xsl:value-of select="generate-id(.)"/>
<xsl:template match="gml:Polygon[not(@gml:id) or not(@srsName)]|
gml:MultiSurface[not(@gml:id) or not(@srsName)]|
gml:LineString[not(@gml:id) or not(@srsName)]|
gml320:Polygon[not(@gml320:id) or not(@srsName)]|
gml320:MultiSurface[not(@gml:id) or not(@srsName)]|
gml320:LineString[not(@gml:id) or not(@srsName)]">
<xsl:element name="gml:{local-name()}"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">

<xsl:attribute name="gml:id"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:value-of select="if (@gml:id != '')
then @gml:id
else if (@gml320:id != '')
then @gml320:id
else generate-id(.)"/>
</xsl:attribute>
<xsl:attribute name="srsName">
<xsl:text>urn:ogc:def:crs:EPSG:6.6:4326</xsl:text>
<xsl:value-of select="if (@srsName != '') then @srsName else 'urn:ogc:def:crs:EPSG:6.6:4326'"/>
</xsl:attribute>
<xsl:copy-of select="@*"/>
<xsl:copy-of select="@*[name() != 'srsName' and local-name() != 'id']"/>
<xsl:apply-templates select="*"/>
</xsl:copy>
</xsl:element>
</xsl:template>

<xsl:template match="gml:*|gml320:*">
<xsl:element name="gml:{local-name()}"
namespace="{if($isUsing2005Schema)
then 'http://www.opengis.net/gml'
else 'http://www.opengis.net/gml/3.2'}">
<xsl:apply-templates select="@*|*"/>
</xsl:element>
</xsl:template>

<!-- INSPIRE / TG2 / Require nilReason attribute to be
Expand Down Expand Up @@ -425,19 +443,19 @@

<!-- Populate PT_FreeText for default language if not existing and it is not null. -->
<xsl:apply-templates select="gco:CharacterString|gmx:Anchor"/>
<!-- only put this in if there's stuff to put in, otherwise we get a <gmd:PT_FreeText/> in output -->
<xsl:if test="(normalize-space(gco:CharacterString|gmx:Anchor) != '') or gmd:PT_FreeText">
<gmd:PT_FreeText>
<xsl:if test="normalize-space(gco:CharacterString|gmx:Anchor) != ''"> <!-- default lang-->
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#{$mainLanguageId}">
<xsl:value-of select="gco:CharacterString|gmx:Anchor"/>
</gmd:LocalisedCharacterString>
</gmd:textGroup>
</xsl:if>
<xsl:call-template name="populate-free-text"/> <!-- other langs -->
</gmd:PT_FreeText>
</xsl:if>
<!-- only put this in if there's stuff to put in, otherwise we get a <gmd:PT_FreeText/> in output -->
<xsl:if test="(normalize-space(gco:CharacterString|gmx:Anchor) != '') or gmd:PT_FreeText">
<gmd:PT_FreeText>
<xsl:if test="normalize-space(gco:CharacterString|gmx:Anchor) != ''"> <!-- default lang-->
<gmd:textGroup>
<gmd:LocalisedCharacterString locale="#{$mainLanguageId}">
<xsl:value-of select="gco:CharacterString|gmx:Anchor"/>
</gmd:LocalisedCharacterString>
</gmd:textGroup>
</xsl:if>
<xsl:call-template name="populate-free-text"/> <!-- other langs -->
</gmd:PT_FreeText>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
Expand Down Expand Up @@ -479,10 +497,10 @@

<xsl:if test="normalize-space(./text()) != '' and string(@codeListValue)">
<xsl:value-of select="java:getIsoLanguageLabel(@codeListValue, $mainLanguage)" />
<!--
<!--
If wanting to get strings from codelists then add gmd:LanguageCode codelist in loc/{lang}/codelists.xml
and use getCodelistTranslation instead of getIsoLanguageLabel. This will allow for custom values such as "eng; USA"
i.e.
i.e.
<xsl:value-of select="java:getCodelistTranslation(name(), string(@codeListValue), string($mainLanguage))"/>
-->
</xsl:if>
Expand Down Expand Up @@ -645,6 +663,26 @@
</xsl:choose>
</xsl:template>

<xsl:template name="correct_ns_prefix_with_namespace">
<xsl:param name="element"/>
<xsl:param name="prefix"/>
<xsl:param name="namespace"/>

<xsl:choose>
<xsl:when test="local-name($element)=name($element) and $prefix != '' ">
<xsl:element name="{$prefix}:{local-name($element)}" namespace="{$namespace}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


<xsl:template match="gmd:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:with-param name="element" select="."/>
Expand All @@ -661,20 +699,21 @@

<!-- Move to GML 3.2.1 when using 2007 version. -->
<xsl:template match="gml320:*[$isUsing2007Schema]">
<xsl:element name="gml:{local-name()}">
<xsl:element name="gml:{local-name()}" namespace="http://www.opengis.net/gml/3.2">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@gml320:*[$isUsing2007Schema]">
<xsl:attribute name="gml:{local-name()}" select="."/>
<xsl:attribute name="gml:{local-name()}" namespace="http://www.opengis.net/gml/3.2" select="."/>
</xsl:template>

<xsl:template match="gml:*|gml320:*">
<xsl:call-template name="correct_ns_prefix">
<xsl:call-template name="correct_ns_prefix_with_namespace">
<xsl:with-param name="element" select="."/>
<xsl:with-param name="prefix"
select="if ($isUsing2005Schema and not($isUsing2007Schema))
then 'gml320' else 'gml'"/>
select="'gml'"/>
<xsl:with-param name="namespace"
select="if($isUsing2005Schema) then 'http://www.opengis.net/gml' else 'http://www.opengis.net/gml/3.2'"/>
</xsl:call-template>
</xsl:template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ Object getRecordAsXML(
isJson ? "json" : "xml"
));
return isJson ? Xml.getJSON(xml) : xml;
//return xml;
}

@ApiOperation(
Expand Down