Skip to content

Commit

Permalink
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 committed Sep 21, 2023
1 parent 4083c63 commit 51c6fa4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 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>
<xsl:if test="nilReason">
"nilReason": "<xsl:value-of select="nilReason"/>",
Expand Down Expand Up @@ -1115,7 +1115,7 @@
<xsl:for-each select="$processSteps">
<processSteps type="object">{
"descriptionObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'description', mrl:description, $allLanguages)"/>
'description', mrl:description, $allLanguages, true())"/>
<xsl:if test="normalize-space(mrl:stepDateTime) != ''">
,"date": "<xsl:value-of select="mrl:stepDateTime//gml:timePosition/text()"/>"
</xsl:if>
Expand All @@ -1125,7 +1125,7 @@
{
"descriptionObject": <xsl:value-of
select="gn-fn-index:add-multilingual-field(
'description', mrl:description, $allLanguages)"/>
'description', mrl:description, $allLanguages, true())"/>
}
<xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
Expand All @@ -1143,7 +1143,7 @@
"organisationObject": <xsl:value-of
select="gn-fn-index:add-multilingual-field(
'description', .//cit:CI_Organisation/cit:name,
$allLanguages)"/>
$allLanguages, true())"/>
<xsl:if test="$individualName != ''">
,"individual":"<xsl:value-of select="gn-fn-index:json-escape($individualName)"/>"
</xsl:if>
Expand Down Expand Up @@ -1248,15 +1248,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>
<xsl:if test="../@gco:nilReason">
"nilReason": "<xsl:value-of select="../@gco:nilReason"/>",
Expand Down Expand Up @@ -1418,7 +1418,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
12 changes: 6 additions & 6 deletions schemas/iso19139/src/main/plugin/iso19139/index-fields/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@
<xsl:for-each select="$processSteps">
<processSteps type="object">{
"descriptionObject": <xsl:value-of select="gn-fn-index:add-multilingual-field(
'description', gmd:description, $allLanguages)"/>
'description', gmd:description, $allLanguages, true())"/>
<xsl:if test="normalize-space(gmd:dateTime) != ''">
,"date": "<xsl:value-of select="gmd:dateTime/gco:*/text()"/>"
</xsl:if>
Expand All @@ -1012,7 +1012,7 @@
{
"descriptionObject": <xsl:value-of
select="gn-fn-index:add-multilingual-field(
'description', gmd:description, $allLanguages)"/>
'description', gmd:description, $allLanguages, true())"/>
}
<xsl:if test="position() != last()">,</xsl:if>
</xsl:for-each>
Expand All @@ -1028,7 +1028,7 @@
{
"organisationObject": <xsl:value-of
select="gn-fn-index:add-multilingual-field(
'description', gmd:organisationName, $allLanguages)"/>
'description', gmd:organisationName, $allLanguages, true())"/>
<xsl:if test="gmd:individualName/gco:CharacterString/text()">
,"individual":"<xsl:value-of select="gn-fn-index:json-escape(gmd:individualName/gco:CharacterString/text())"/>"
</xsl:if>
Expand Down Expand Up @@ -1109,11 +1109,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>
<xsl:if test="../@gco:nilReason">
"nilReason": "<xsl:value-of select="../@gco:nilReason"/>",
Expand Down Expand Up @@ -1270,7 +1270,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 51c6fa4

Please sign in to comment.