xquery version "1.0"; declare namespace r = "http://www.w3.org/2005/sparql-results#"; declare option exist:serialize "method=xhtml media-type=text/html"; (: sparql query to get the capital for each country :) declare variable $query := " PREFIX rdf: PREFIX mon: SELECT distinct ?name ?population WHERE { ?country rdf:type mon:Country ; mon:name ?name ; mon:population ?population. ?capital mon:name ?cname. }"; (: set up target for query - note the xml entity in the querystring :) declare function local:execute-sparql($query as xs:string) { let $sparql := concat("http://localhost:8080/openrdf-workbench/repositories/Benjamin-mondial/query?format=xml&query=",escape-uri($query, true())) return doc($sparql) }; (: return html :) European Country Population

European Country Population

{ for $tuple in local:execute-sparql($query)//r:result let $name := $tuple/r:binding[@name="name"]/r:literal let $population := $tuple/r:binding[@name="population"]/r:literal return }
NAME POPULATION
{$name} {$population}