Skip to content

Commit

Permalink
[BP] Indexing / Do not create empty object if no text (#7349)
Browse files Browse the repository at this point in the history
Follow #7294

Clarify usage of the function which can return an element or text.
  • Loading branch information
fxprunayre authored and josegar74 committed Sep 21, 2023
1 parent 7d6a395 commit e60c4d5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<xsl:attribute name="type" select="'object'"/>{
<xsl:if test="$organisationName">
"organisationObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'organisation', $organisationName, $languages)"/>,
'organisation', $organisationName, $languages, true())"/>,
</xsl:if>
"role":"<xsl:value-of select="$role"/>",
"email":"<xsl:value-of select="gn-fn-index:json-escape($email[1])"/>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1073,15 +1073,15 @@
function/text())"/>",
<xsl:if test="normalize-space(url) != ''">
"urlObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'url', url/*, $allLanguages)"/>,
'url', url/*, $allLanguages, true())"/>,
</xsl:if>
<xsl:if test="normalize-space(title) != ''">
"nameObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'name', title/*, $allLanguages)"/>,
'name', title/*, $allLanguages, true())"/>,
</xsl:if>
<xsl:if test="normalize-space(description) != ''">
"descriptionObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'description', description/*, $allLanguages)"/>,
'description', description/*, $allLanguages, true())"/>,
</xsl:if>
"applicationProfile": "<xsl:value-of select="gn-fn-index:json-escape(
applicationProfile/text())"/>"
Expand Down Expand Up @@ -1187,15 +1187,15 @@
else ''"/>",
<xsl:if test="normalize-space(cit:linkage) != ''">
"urlObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'url', cit:linkage, $allLanguages)"/>,
'url', cit:linkage, $allLanguages, true())"/>,
</xsl:if>
<xsl:if test="normalize-space(cit:name) != ''">
"nameObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'name', cit:name, $allLanguages)"/>,
'name', cit:name, $allLanguages, true())"/>,
</xsl:if>
<xsl:if test="normalize-space(cit:description) != ''">
"descriptionObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'description', cit:description, $allLanguages)"/>,
'description', cit:description, $allLanguages, true())"/>,
</xsl:if>
"function":"<xsl:value-of select="cit:function/cit:CI_OnLineFunctionCode/@codeListValue"/>",
"applicationProfile":"<xsl:value-of select="gn-fn-index:json-escape(cit:applicationProfile/gco:CharacterString/text())"/>",
Expand Down Expand Up @@ -1353,7 +1353,7 @@
<xsl:attribute name="type" select="'object'"/>{
<xsl:if test="$organisationName">
"organisationObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'organisation', $organisationName, $languages)"/>,
'organisation', $organisationName, $languages, true())"/>,
</xsl:if>
"role":"<xsl:value-of select="$role"/>",
"email":"<xsl:value-of select="gn-fn-index:json-escape($email)"/>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,11 +1054,11 @@
"urlObject":{"default": "<xsl:value-of select="gn-fn-index:json-escape(gmd:linkage/gmd:URL)"/>"},
<xsl:if test="normalize-space(gmd:name) != ''">
"nameObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'name', gmd:name, $allLanguages)"/>,
'name', gmd:name, $allLanguages, true())"/>,
</xsl:if>
<xsl:if test="normalize-space(gmd:description) != ''">
"descriptionObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'description', gmd:description, $allLanguages)"/>,
'description', gmd:description, $allLanguages, true())"/>,
</xsl:if>
"function":"<xsl:value-of select="gmd:function/gmd:CI_OnLineFunctionCode/@codeListValue"/>",
"applicationProfile":"<xsl:value-of select="gn-fn-index:json-escape(gmd:applicationProfile/gco:CharacterString/text())"/>",
Expand Down Expand Up @@ -1211,7 +1211,7 @@
<xsl:attribute name="type" select="'object'"/>{
<xsl:if test="$organisationName">
"organisationObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'organisation', $organisationName, $languages)"/>,
'organisation', $organisationName, $languages, true())"/>,
</xsl:if>
"role":"<xsl:value-of select="$role"/>",
"email":"<xsl:value-of select="gn-fn-index:json-escape($email[1])"/>",
Expand Down
17 changes: 16 additions & 1 deletion web/src/main/webapp/xslt/common/index-utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
}
```
A multilingual field in ISO19139 looks like:
```xml
<gmd:title xsi:type="gmd:PT_FreeText_PropertyType">
Expand All @@ -204,6 +205,20 @@
<dc:title xml:lang="en">...
<dc:title xml:lang="fr">...
```
Use this function in 2 modes:
* Adding a new field (using copy-of because output is an XML element.
```xsl
<xsl:copy-of select="gn-fn-index:add-multilingual-field(
$roleField, $organisationName, $languages)"/>
```
* Populating a JSON property in an existing object (using value-of, output is text)
If the element is empty, `{}` is returned.
```xsl
"organisationObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'organisation', $organisationName, $languages, true())"/>,
```
-->
<xsl:function name="gn-fn-index:add-multilingual-field" as="node()*">
<xsl:param name="fieldName" as="xs:string"/>
Expand Down Expand Up @@ -294,7 +309,7 @@
</xsl:for-each>
</xsl:variable>

<xsl:if test="count($textObject[. != '']) > 0">
<xsl:if test="count($textObject[. != '']) > 0 or $asJson">
<xsl:choose>
<xsl:when test="$asJson">
<xsl:if test="$isArray and position() = 1">[</xsl:if>
Expand Down

0 comments on commit e60c4d5

Please sign in to comment.