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

Yves Forkl Y.Forkl at srz.de
Fri Oct 17 16:12:21 PDT 2008


from a very simple XML input, I would like to create a CSV-like output, 
putting each record (as I see them) in a line of its own, with its 
fields separated by some delimiter like a semicolon.

It works quite well, except that a space gets inserted at the front of 
each line starting from the second line in the output.

My demo input is:

<?xml version='1.0'?>

My XQuery file has:

declare namespace saxon="http://saxon.sf.net/";
declare option saxon:output "method=text";

let $entries := /list/entry

for $property1 in distinct-values($entries/property1),
     $property2 in distinct-values($entries[property1 = 
   let $selected_entries := $entries[property1 = $property1 and
                                            property2 = $property2]
   order by $property1, $property2
         ($property1, $property2,
                    sum(for $quantity in $selected_entries/quantity
                        return xs:decimal(replace($quantity, ",", ".")))),

The result as obtained with Saxon is:


It is the space at the beginning of the second line that I can't get 
away with. Can you explain what I am doing wrong here and maybe suggest 
a solution?

(Another question: Within my "quantity" elements, I use the German 
decimal separator which is a comma. Is there a more elegant way than 
translating it to a dot and back, like above, when summing up the values 
found in this element?)


More information about the talk mailing list