Add twoletter parameter to countries.xsl

This allows for setting the value of the select field only to the
two-letter country code (which is the only one understood by `fsfe-cd`)
This commit is contained in:
Linus Sehn 2022-11-17 16:06:59 +01:00
parent 5603bcc54e
commit ff745c934d

View File

@ -1,19 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- showing a dropdown select menu with all countries in /tools/countries.**.xml -->
<xsl:template name="country-list">
<xsl:param name="required" select="'no'" />
<xsl:param name="class" select="''" />
<xsl:param name="subset" select="''" />
<xsl:param name="twoletter" select="'no'" />
<xsl:element name="select">
<xsl:attribute name="id">country</xsl:attribute>
<xsl:attribute name="name">country</xsl:attribute>
<!-- if called with a "class" value, set it as the CSS class -->
<xsl:choose>
<xsl:when test="$class != ''">
<xsl:attribute name="class"><xsl:value-of select="$class" /></xsl:attribute>
<xsl:attribute name="class"
><xsl:value-of select="$class"
/></xsl:attribute>
</xsl:when>
</xsl:choose>
<!-- when called with the required="yes" param, add the attribute
@ -21,27 +23,41 @@
<xsl:choose>
<xsl:when test="$required = 'yes'">
<xsl:attribute name="required">required</xsl:attribute>
<option></option> <!-- this will force people to pick a choice actively -->
<option></option>
<!-- this will force people to pick a choice actively -->
</xsl:when>
</xsl:choose>
<!-- loop over all countries in countries.**.xml -->
<xsl:choose>
<!-- if subset is defined, only display those that have as attribute: $subset="yes" -->
<xsl:when test="$subset != ''">
<xsl:for-each select="/buildinfo/document/set/country[@*[name() = $subset] = 'yes']">
<xsl:for-each
select="/buildinfo/document/set/country[@*[name() = $subset] = 'yes']"
>
<xsl:sort select="." lang="en" />
<xsl:call-template name="country-list-options" />
</xsl:for-each>
</xsl:when>
<!-- otherwise, just display all countries -->
<xsl:otherwise>
<xsl:for-each select="/buildinfo/document/set/country">
<xsl:sort select="." lang="en" />
<xsl:call-template name="country-list-options" />
</xsl:for-each>
<xsl:choose>
<xsl:when test="$twoletter = 'yes'">
<xsl:for-each select="/buildinfo/document/set/country">
<xsl:sort select="." lang="en" />
<xsl:call-template name="country-list-options-2-letter" />
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="/buildinfo/document/set/country">
<xsl:sort select="." lang="en" />
<xsl:call-template name="country-list-options" />
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:element> <!-- /select -->
</xsl:element>
<!-- /select -->
</xsl:template>
<xsl:template name="country-list-options">
@ -51,8 +67,18 @@
<xsl:value-of select="@id" />|<xsl:value-of select="." />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element> <!-- /option -->
</xsl:element>
<!-- /option -->
</xsl:template>
<xsl:template name="country-list-options-2-letter">
<!-- will output: <option value="ZZ">Fooland</option> -->
<xsl:element name="option">
<xsl:attribute name="value">
<xsl:value-of select="@id" />
</xsl:attribute>
<xsl:value-of select="." />
</xsl:element>
<!-- /option -->
</xsl:template>
</xsl:stylesheet>