Re: [xsl] XSLT2 Change country name to alpha-2

Subject: Re: [xsl] XSLT2 Change country name to alpha-2
From: "LEGAULT, PHILLIP plegault@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 3 Jul 2023 00:45:17 -0000
Tried it like this:
<codes>
  <country alpha-2="US" name =	"United States"/>
</codes>
<xsl:key name="alpha-by-name" match="codes/country" use="@name"/>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
            <primarysourcecountry><xsl:value-of select="key('alpha-by-name',
'/records/sf:ConsumerCountry_GCC__c',
$codes)/@alpha-2"/></primarysourcecountry>

Does not work.



-----Original Message-----
From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Sunday, July 2, 2023 7:20 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [EXTERNAL]Re: [xsl] XSLT2 Change country name to alpha-2


On 02.07.2023 13:09, LEGAULT, PHILLIP plegault@xxxxxxxxxx wrote:
> I get the country in like United States.
>
>
>
> I have this,


Then declare a key

 B  <xsl:key name="alpha-by-name" match="codes/country" use="@name"/>


load e.g. <xsl:param name="codes" select="doc('codes.xml')"/> and where you
need the code from the country name use e.g.

 B  key('alpha-by-name', country, $codes)/@alpha-2


I wonder how often that will fail for e.g.

>
> <codes>
>
>
>
>    <country alpha-2="BS" name =	"Bahamas (the)"/>
>
>
or
>
>    <country alpha-2="IO" name =	"British Indian Ocean Territory (the)"/>
>
>
or
>
>    <country alpha-2="KY" name =	"Cayman Islands (the)"/>

Current Thread