Question

In Oracle Service Bus I need 'ISO 3166-1 alpha-2' and 'ISO 3166-1 alpha-3' country codes. At the moment I'm using Java Callout to get the same (which I would like to avoid).

I'm new to both these technologies and unaware of the standard practices so just wanted to check your opinion.

1. I was just wondering if there are any XQuery libraries which could provide country codes.
2. Considering most probably these values are going to be constant, is it okay to handwrite the function.

Thanks.

Was it helpful?

Solution

I don't know of an existing XQuery module that provides that functionality. But as all codes are available from the ISO Online Browsing Platform, you cal easily build your own.

I quickly generated an XML document from all currently assigned codes, which can be found at https://gist.github.com/LeoWoerteler/9388743. Using that, the conversion from alpha-2 to alpha-3 codes could be done as follows:

declare variable $iso_3166-1 := doc('iso_3166-1.xml')/iso_3166-1;

declare function local:alpha2-to-alpha3($code) as xs:string {
  $iso_3166-1/country[@alpha-2 = $code]/@alpha-3
};

local:alpha2-to-alpha3('US') (: ==> 'USA' :)

OTHER TIPS

You could use the ISO 2 letter country codes from here: http://www.codesynthesis.com/projects/xsstl/xsstl/iso3166-country-code.xsd

With that document you could lookup countries by their country code using something like the following:

declare namespace xsd = "http://www.w3.org/2001/XMLSchema";

replace(//xsd:enumeration[@value eq 'BV']/following-sibling::comment()[1], "<!-- (.*) -->", "$1")

Personally I would transform that Schema document into a simple XML document, extracting the country names from the comments so that I do not have to query the comments themselves.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top