[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Whitespace problem in CSV-like output

John Snelson john.snelson at oracle.com
Mon Oct 20 12:12:04 PDT 2008


  Whitespace problem in CSV-like output
Yves Forkl wrote:
> 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.

Well, DataDirect's method seems to require you to construct a custom XML 
structure, and specify a implementation specific serialization method. 
Your current method requires that you create some strings, and join them 
with string-join(). I'm not sure there's a lot of difference between the 
two.

I agree that using a space as a separator between atomic items when 
outputting them can be confusing - but at other times it's actually very 
useful. It's now a widespread practice in both XQuery and XSLT 2.0, so I 
don't know how much it could be changed.

>>> 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).

It would seem to be a bug if it drops the last line feed in the output.

John

-- 
John Snelson, Oracle Corporation            http://snelson.org.uk/john
Berkeley DB XML:            http://oracle.com/database/berkeley-db/xml
XQilla:                                  http://xqilla.sourceforge.net


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.