Hi Emmanuelle,
please don't forget to include the mailing list in your mails, so others can also benefit from the questions (and other people might answer you faster or better than I can).
The CSV serialization works just on the element name as far as I can remember. You could simply rename the node, e.g.
let $destinataire := $creation/persName[@type='destinataire'] update rename node . as "pers1"
For help with XQuery Update, oyu might also want to take a look at the docs: http://docs.basex.org/wiki/Update
Cheers, Dirk
On 10/23/2014 03:12 PM, Emmanuelle Morlock wrote:
Hi again there's something strange happening with the csv serialization of my query
Two of my variables have the same element but are distinguished by their attribute
declare option output:method "csv"; declare option output:csv "header=yes, separator=semicolon"; for $lettre in db:open('myBD')//TEI where $lettre//opener//addrLine[not(contains(.,'Adresse ?'))] let $creation := $lettre//profileDesc/creation let $titre := $lettre//teiHeader//title let $date := $lettre//profileDesc//date let $destinataire := $creation/persName[@type='destinataire'] let $expediteur := $creation/persName[@type='expediteur'] return
<csv> <record>data({$date}) data({$expediteur} data({$titre} data({$destinataire}) </record> </csv>
the result creates one field 'persName' with two values (separated by a comma), whereas I wanted 2 fields
date;persName;title 01/01/2000;Pierre Martin,Jean Dupond;Title
what shoud I do to avoid that and get as a result something like :
date;persName1;title:persName2 01/01/2000;Pierre Martin;Title;Jean Dupond
thanks emmanuelle
Le 23/10/2014 14:31, Dirk Kirsten a écrit :
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 mailto: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
-- Dirk Kirsten, BaseX GmbH, http://basex.org http://basex.org/ |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22