(:looks up a legacy name in the country lookups xml file and finds a JDE match:)
declare function lookups:lookupCountry($legacyCountry as xs:string) as xs:string
{
(:location of the country lookups xml:)
let $countryLookupsXml := doc("http://x/CountryLookups.xml")
let $foundNode := $countryLookupsXml/Countries/Country[normalize-space(upper-case(@LegacyName)) = normalize-space(upper-case($legacyCountry))]
return
if (exists($foundNode))
then
data($foundNode/@DRKY)
else
normalize-space(upper-case($legacyCountry))
};