Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put each XQuery result on a new line

Is it possible to put each XQuery result on a new line? I thought I remembered there was an attribute to set at the beginning of the document, but can't remember. :/

I have this .xq file:

(: declare default element namespace "http://www.w3.org/2001/XMLSchema"; :)
for $x at $i in doc("zoo.xml")//animal
return <li>{$i}. {$x/name/text()}</li> 

I get correct results, but all of them are on a single line, when I really want something like:

<li>1. Zeus</li>
<li>2. Fred</li>
...

Is this possible? Thanks in advance for your answers! :)

like image 847
Chris V. Avatar asked Feb 07 '12 19:02

Chris V.


1 Answers

...you can add a newline string as second part of the return clause:

(: declare default element namespace "http://www.w3.org/2001/XMLSchema"; :)
for $x at $i in doc("zoo.xml")//animal
return (<li>{$i}. {$x/name/text()}</li>, '&#xa;')

The way how results are serialized also depends on the specific XQuery processor.

like image 160
Christian Grün Avatar answered Oct 24 '22 05:10

Christian Grün