nobleb
nobleb

Reputation: 129

Line feed leaving extra space at end of line in XQuery

I have an application where I create a .csv file and then create a .xlsx file from the .csv file. The problem I am having now is that the end of rows in the .csv have a trailing space. My database is in MarkLogic and I am using a custom REST endpoint to create this. The code where I create the .csv file is:

document{($header-row,for $each in $data-rows return fn:concat('
',$each))}

I pass in the header row then pass each data row with a carriage return and a line feed at the beginning. I do this to put the cr/lf at the end of the header and then each of the other lines except for the last one. I know my data rows do not have the space at the end. I have tried to normalize the space around $each and the extra space is still present. It seems to be tied to the line feed. Any suggestions on getting rid of that space?

Example of current output:

Name,Email,Phone 

Bill,[email protected],999-999-9999 

Steve,[email protected],999-999-9999 

Bob,[email protected],999-999-9999 

. . .

Upvotes: 1

Views: 248

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66783

You are creating a document that is text() node from a sequence of strings. When those are combined to create a single text(), they will be separated by a space. For instance, this:

text{("a","b","c")}

will produce this:

"a b c"

Change your code to use string-join() to join your $header-row and sequence of $data-rows string values with the 
 separator:

document{ string-join(($header-row, $data-rows), "
") }

Upvotes: 2

Related Questions