Skip to content

Commit

Permalink
improved schematron localisation
Browse files Browse the repository at this point in the history
- added xslt helper function to replace placeholders
- made sure shared strings can be used for the schematron localisation (schematron-shared.xml)
- fix in iso_svrl_for_xslt2.xsl to make sure $loc is also used when wrapped in a function
  • Loading branch information
joachimnielandt committed Feb 18, 2025
1 parent 711f9f2 commit 3f3058a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@
xmlns:schold="http://www.ascc.net/xml/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
xmlns:svrl="http://purl.oclc.org/dsdl/svrl"
version="1.0"
xmlns:geonet="http://www.fao.org/geonetwork"
version="2.0"

>

Expand Down Expand Up @@ -210,7 +211,25 @@
<axsl:param name="thesaurusDir"/>
<axsl:param name="rule"/>

<axsl:variable name="loc" select="document(concat('../loc/', $lang, '/', $rule, '.xml'))"/>
<!-- Retrieve localisation entries (one file specific to the rule, the other file is shared by all schematron). Fallback language is English. -->
<axsl:variable name="loc">
<axsl:choose>
<axsl:when test="document(concat('../loc/', $lang, '/', $rule, '.xml'))">
<axsl:copy-of select="document(concat('../loc/', $lang, '/', $rule, '.xml'))"/>
</axsl:when>
<axsl:otherwise>
<axsl:copy-of select="document(concat('../loc/', 'eng', '/', $rule, '.xml'))"/>
</axsl:otherwise>
</axsl:choose>
<axsl:choose>
<axsl:when test="count(document(concat('../loc/', $lang, '/', 'schematron-shared.xml')))">
<axsl:copy-of select="document(concat('../loc/', $lang, '/', 'schematron-shared.xml'))"/>
</axsl:when>
<axsl:otherwise>
<axsl:copy-of select="document(concat('../loc/', 'eng', '/', 'schematron-shared.xml'))"/>
</axsl:otherwise>
</axsl:choose>
</axsl:variable>
</xsl:template>

<!-- Overrides skeleton.xsl -->
Expand Down Expand Up @@ -525,7 +544,7 @@
<xsl:template name="svrl-text">
<svrl:text>
<xsl:choose>
<xsl:when test="starts-with(., '$loc')">
<xsl:when test="contains(., '$loc/strings/')">
<xsl:element name="xsl:copy-of">
<xsl:attribute name="select">
<xsl:apply-templates mode="text"/>
Expand Down Expand Up @@ -570,7 +589,7 @@
<xsl:if test=" string( $name )">
<axsl:attribute name="name">
<xsl:choose>
<xsl:when test="starts-with($name, '$loc')">
<xsl:when test="contains($name, '$loc/strings/')">
<axsl:value-of>
<xsl:attribute name="select">
<xsl:value-of select="$name"/>
Expand Down
14 changes: 14 additions & 0 deletions web/src/main/webapp/xsl/utils-fn.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,19 @@
</xsl:choose>
</xsl:function>

<!-- Replace a given list of $placeholders by a list of respective $values in the given $string. -->
<xsl:function name="geonet:replacePlaceholders">
<xsl:param name="string"/>
<xsl:param name="placeholders"/>
<xsl:param name="values"/>
<xsl:choose>
<xsl:when test="count($placeholders)=1">
<xsl:value-of select="replace($string, $placeholders[position()=1], $values[position()=1])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="geonet:replacePlaceholders(replace($string, $placeholders[position()=1], $values[position()=1]), $placeholders[position()>1], $values[position()>1])"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>

</xsl:stylesheet>

0 comments on commit 3f3058a

Please sign in to comment.