This happens because the serializer takes a sequence of strings and combines them into a single text node using a single space as the separator. This behaviour is defined in section 2 of the serialization spec. The answer is to use string-join to concatenate the rows without separation:
 
string-join(
for $row in ("_1_" , "_2_" , "_3_")
return
concat(local:sequence-to-csv($row),$RS)
, "")
 
Michael Kay
http://www.saxonica.com/



From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Cecil New
Sent: 01 February 2008 16:50
To: saxon-help@lists.sourceforge.net
Subject: [saxon] text output method

I am creating a CSV file from a collection of xml documents using the text output method.  The second and following lines have a blank at the beginning.  I cannot figure out how to suppress it.  The query below reproduces the problem in the small.

declare option saxon:output "method=text";
declare option saxon:output "indent=no";
declare variable  $FS := ',';
declare variable  $RS := '
';
declare function local:sequence-to-csv($seq) as xs:string
{
    string-join($seq,$FS)
};
for $row in ("_1_" , "_2_" , "_3_")
return
concat(local:sequence-to-csv($row),$RS)

Here is the output where you can see the leading blank.  Thanks for any advice!

>java %CP% net.sf.saxon.Query -t xqtest.xq
Saxon 9.0.0.2J from Saxonica
Java version 1.5.0_11
Analyzing query from xqtest.xq
Analysis time: 156 milliseconds
_1_
 _2_
 _3_
Execution time: 16 milliseconds