service namespace quote="www.ethz.ch" port:2002; declare execution sequential; declare function quote:symbolLookup($a) { if (doc(concat(concat("http://www.trynt.com/symbol-lookup-api/v2/?s=",data($a)),"&fo=xml&f=0"))//company-name eq "No match found. Please try again.") then for $s1 in fn:doc(data(concat(concat("http://app.quotemedia.com/data/lookupSymbols.xml?searchString=",data($a)),"&resultsPerPage=500")))//lookupdata where $s1//exchange eq "NGS" return {data($s1//longname)} {data($s1//shortname)} else for $s2 in doc(concat(concat("http://www.trynt.com/symbol-lookup-api/v2/?s=",data($a)),"&fo=xml&f=0")) return {data($s2//company-name)} {data($s2//symbol)} };