Hello Emmanuelle,
You're very welcome to ask, even if its basic (or looks basic to you). We all started with XQuery at one point in time...
In this case, it is even simpler than you expected I guess. As you want to serialize the output as csv, you don't even need the serialize() function. You can simply set in the prolog of your XQuery
declare option output:method "csv";
and your output will be automatically converted from XML to CSV. There is an example for CSV at http://docs.basex.org/wiki/Serialization, you can also define options in the prolog.
Also, I noticed that you do $lettre//profileDesc/creation quite often. // is a quite costly operation, so you might want to put this into a separate variable which you then use - The optimizer might do that for you, but it is also shorter and cleaner to write.
Cheers, Dirk
On Thu, Oct 23, 2014 at 12:24 PM, Emmanuelle Morlock < emmanuelle.morlock@mom.fr> wrote:
Hi all,
I'm trying to do some xquery with the GUI in a standalone install. As I'm beginning with xquery, I rely a lot on the examples given in the doc. But I don't manage to be successful with http://docs.basex.org/wiki/CSV_Module for what I need.
I'd like to get a result formatted in csv (separator : ';' or whatever) so tha I can directly import in a spreadsheet the results exported file.
Here's the begining of my query :
for $lettre in db:open('myDB')//TEI where $lettre//opener//addrLine[not(contains(.,'Adresse ?'))] let $title := $lettre//teiHeader//title let $destinataire := $lettre//profileDesc/creation/persName[@type='destinataire'] let $expediteur := $lettre//profileDesc/creation/persName[@type='expediteur'] let $date := $lettre//profileDesc//date let $locName := $lettre//profileDesc/creation/location/placeName[@type='PlaceExp'] let $locGeo := $lettre//profileDesc/creation/location/geo
then I guess I should have something like :
- a variable for the option... is let $options := {'separator':';'}
correct ? something to put all the variable as a result let $fields := ... ? then return csv:serialize ($fields, $options)
??? thanks for helping even if this sounds too basic !
best
emmanuelle
-- Emmanuelle Morlock IGE CNRS - soutien aux projets d'édition TEI - humanités numériques UMR 5189 HISoMA http://www.hisoma.mom.fr/ 04 72 71 58 40 06 85 84 69 16 @emma_morlock