2

I grab some data from XML and translate it to Turtle/N3. I want to add @prefix and namespace URLs at the beginning. The original XML is something like:

<xxx>
<country 
name="XX"
population="NN">
...
</country>
...
</xxx>

I write the XQuery:

declare function local:genPopulation()as xs:string* {
let $countries:=doc("mondial-3.0.xml")//country
for $elt in $countries
let $population := $elt/@population[1]
let $countryName := $elt/@name
return (concat(":",$countryName,":population :",$population,".&#xa;"))
};
"&#xa;","@prefix rdf: <http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#> .","&#xa;",
"@prefix : <http://lyle.smu.edu/cse7347/> .","&#xa;",
local:genPopulation()

The output is:

<?xml version="1.0" encoding="UTF-8"?>
 @prefix rdf: &lt;http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#&gt; . 
 @prefix : &lt;http://lyle.smu.edu/cse7347/&gt; . 
 :Albania:population :3249136.
 :Andorra:population :72766.
 ..
 ...

The output translate the original "<" and ">" to "<" and ">". How to keep these string unchanged? I want the output like:

 @prefix rdf: <http://www.w3.org/1999/02/22‐rdf‐syntax‐ns#> . 
 @prefix : <http://lyle.smu.edu/cse7347/> . 
 :Albania:population :3249136.
 ...

What should I do?enter image description here

Ankit Bhardwaj
  • 754
  • 8
  • 27
Mayoco
  • 87
  • 1
  • 10
  • 3
    Your output is being serialised as XML. Try adding a serialisation option. declare output:method "text"; – chrisis Apr 17 '16 at 06:50
  • @chrisis I add 'declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; declare option output:method "text";'at the beginning and it works! Thank you! – Mayoco Apr 17 '16 at 15:23
  • @chrisis Please make your comment into a reply so it can be properly acknowledged and voted up. – Joe Wicentowski Apr 19 '16 at 01:02

1 Answers1

2

The output is being serialised as XML. To serialise as text add

declare namespace output = "w3.org/2010/xslt-xquery-serialization";
declare output:method "text"; 
chrisis
  • 1,983
  • 5
  • 20
  • 17