Thanks Christian.
I missed the option of adding a comma after the initial file:write command (the editor was constantly asking for a return command).

Thanks again. It worked perfectly (although I must admit I used the dirty option, as the CSV examples are mainly on adapting CSV into XML, while I need the other direction).

Noam

On Wed, May 27, 2015 at 9:40 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Noam,

>  let $csv := csv:serialize($result)
>   return file:write-text($out, $csv)
>
> The CVS that comes out only includes one line [...]

As there are unlimited ways to represent XML nodes as CSV, there is no
way to automatically a representation that always works best. For more
information on creating an XML representation that will yield good
results as CSV, please check out the documentation on our CSV Module
[1].

> Now this works, but I can't seem to find a way to add the headers to the
> first line of the file.

Obviously, I would recommend you to use the existing CSV features,
because it will take care of all the usal nifty details. However, here
is one simple way to let your file start with a header line:

file:write-text-lines($out, 'Name,Host,Path,Count,Time'),
let $result := concat ($name,',',$host,',',$path,',',$count,',',$time)
return file:append-text-lines($out, $result)

Hope this helps,
Christian

[1] http://docs.basex.org/wiki/CSV_Module