@Override
		public Sequence call(XPathContext context, Sequence[] arguments)
		{
			Sequence seq = null;
			String xml = "";
			
			// Read in the argument into a string
			String locationStr = null;
			try {
				locationStr = arguments[0].iterate().next().getStringValue();
			} catch (XPathException e) {
				locationStr = "";
			}
			
			try
			{
				// Saxon is WONDERFUL and removes escaped characters, so we must re-escape them
				// Using the Apache Commons Lang's org.apache.commons.lang3.StringEscapeUtils
				locationStr = StringEscapeUtils.escapeXml(locationStr);
				
				String line; String json = "";
				URL url = new URL("http://api.geonames.org/search?q=" + locationStr + "&maxRows=1&username=rwb3y&type=json");
				BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
				while ((line = in.readLine()) != null) {
					json += line;
				}
				JSONObject obj = new JSONObject(json);
				
				if (obj != null && obj.has("geonames") && !obj.isNull("geonames")) {
					// read the first item
					JSONArray res = obj.getJSONArray("geonames");
					JSONObject cur = res.getJSONObject(0); // read in the first one
					
					// Build an XML object out of the results
					xml = "<return original=\""+locationStr+"\">";
					xml += "<geonamesid>"+cur.getInt("geonameId")+"</geonamesid>";
					xml += "<name>"+cur.getString("name")+"</name>";
					xml += "<admincode1>"+cur.getString("adminCode1")+"</admincode1>";
					xml += "<country>"+cur.getString("countryName")+"</country>";
					xml += "<lat>"+cur.getDouble("lat")+"</lat>";
					xml += "<lon>"+cur.getDouble("lng")+"</lon>";
					xml += "</return>";
					
					
					
				} else {
					// nothing was parsed
					xml = "<return original=\""+locationStr+"\">";
					xml += "</return>";
				}
				


			}
			catch (Exception sae)
			{
				// If something went wrong, then just return the value "unparseable" to Saxon.
				// nothing was parsed
				xml = "<return>\n";
				xml += "</return>";
			}
			

			// Parse XML into an XdmNode
			Processor proc = new Processor(false);
	        DocumentBuilder builder = proc.newDocumentBuilder();
	        
	        try {
	        	XdmNode xdm = builder.build(new StreamSource(new StringReader(xml)));
	        	seq = xdm.getUnderlyingValue();
	        } catch (Exception sae) {}

			return seq;

		}