[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: XSLT2 Change country name to alpha-2
On 02.07.2023 12:51, LEGAULT, PHILLIP plegault@xxxxxxxxxx wrote: > > Is there an way to convert country name to alpha-2? > You could consider a REST API that gives you the information; most REST API these days are primarily returning JSON as the response so processing with XSLT 3 instead of XSLT 2 is easier e.g. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" B version="3.0" B xmlns:xs="http://www.w3.org/2001/XMLSchema" B exclude-result-prefixes="#all" B expand-text="yes"> B <xsl:template match="country"> B B B <xsl:copy> B B B B B <name>{.}</name> B B B B B <cca2>{json-doc('https://restcountries.com/v3.1/name/' || . || '?fields=cca2')?*?cca2}</cca2> B B B </xsl:copy> B </xsl:template> B <xsl:mode on-no-match="shallow-copy"/> </xsl:stylesheet> for the input <countries> B <country>USA</country> B <country>Deutschland</country> </countries> gives me <countries> <country><name>USA</name><cca2>US</cca2></country> <country><name>Deutschland</name><cca2>DE</cca2></country> </countries> Of course if a REST API has an option to return XML instead of JSON you can easily `doc` to "call it" and then use XPath 2 expressions on the returned document to extract the code.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|