用于iso国家代码的XQuery函数或库?

时间:2014-03-05 15:11:14

标签: xquery osb

在Oracle Service Bus中,我需要'ISO 3166-1 alpha-2'和'ISO 3166-1 alpha-3'国家/地区代码。 目前我正在使用Java Callout来获得相同的内容(我想避免使用它)。

我对这两种技术都不熟悉并且没有意识到标准做法,所以只想查看您的意见。

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.

感谢。

2 个答案:

答案 0 :(得分:3)

我不知道提供该功能的现有XQuery模块。但由于所有代码都可以从ISO Online Browsing Platform获得,因此您可以轻松构建自己的代码。

我从所有当前分配的代码中快速生成了一个XML文档,可以在https://gist.github.com/LeoWoerteler/9388743找到。使用它,从 alpha-2 alpha-3 代码的转换可以按如下方式进行:

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' :)

答案 1 :(得分:0)

您可以使用此处的ISO 2字母国家/地区代码:http://www.codesynthesis.com/projects/xsstl/xsstl/iso3166-country-code.xsd

使用该文档,您可以使用以下内容按国家/地区代码查找国家/地区:

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

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

我个人会将Schema文档转换为一个简单的XML文档,从注释中提取国家名称,这样我就不必自己查询注释了。