[xquery-talk] Whitespace problem in CSV-like output

Yves Forkl Y.Forkl at srz.de
Mon Oct 20 13:00:40 PDT 2008

John Snelson wrote:
> Yves Forkl wrote:
>> It is a bit disappointing to see that XQuery does not offer a simple, 
>> general method to create CSV-type files, at least not in my case.
> What would be simpler than what you have written here?

Well... Maybe an extension function like the one DataDirect XQuery seems 
to offer, as he have learned? :-) Seriously, I was somehow puzzled about 
the complexity of the whitespace problem in the simple task of writing 
out some fields into the lines of a file.

>> NB: While the names of the functions seem to suggest that the line 
>> feed should rather be appended in my:join-records-into-lines than in 
>> my:join-fields-into-record, I don't see any easy way to do this.
> Redefine your functions like this:
> declare function my:join-fields-into-record
>   ( $fields as xs:string*,
>     $delimiter as xs:string ) as xs:string {
>       string-join($fields, $delimiter)
> } ;
> declare function my:join-records-into-lines
>   ( $records as xs:string* ) as xs:string {
>       string-join($records, "
> } ;

Sorry for being so terse. I meant: It would be natural to change the 
functions exactly this way, but this will drop the line feed of the last 
line in the output, which would be undesirable. So I prefer to keep the 
functions unchanged, irrespectively of their slightly misleading names 
(or rather use text nodes than functions to get whitespace right).


More information about the talk mailing list