Re: FW: dynamic traversal of csv records

Daniel Dekany <[email protected]> Fri, 25 Feb 2005 02:16:24 +0100
Newsgroups gmane.comp.text.fmpp
Message-ID <[email protected]>
Thursday, February 24, 2005, 10:24:19 PM, Ralf Hauser wrote:

> -----Original Message-----
> From: Ralf Hauser [mailto:[email protected]] 
> Sent: Thursday, February 24, 2005 8:16 PM
> To: '[email protected]'
> Subject: dynamic traversal of csv records
>
> How would I dynamically traverse through my csv data?
>
> Basically I want not to access the columns of the table by name, but by
> position. E.g. instead of 
>   <#list flowers as flower>
>      <tr><td>${flower.name}...
> as in http://fmpp.sourceforge.net/dataloader.html#key_csv, I would want to
> just access
>   <#list flowers as flower>
>      <tr><td>${flower.1}...
> and "1" being column 1
>
> Also, I would need an inner loop if I not only don't want to use the column
> name to access the field values, but also don't know ahead of time how many
> columns there are.

You can use the "headers" sub-variable to dynamically query the number
of columns and the name of columns. OK, you don't have names... actually
it's a problem that annoys me for a while, since it's sometimes not easy
to ensure that the first row with header names exists... I will look
into this tomorrow. I hope...

> I see in 
> http://freemarker.org/docs/ref_directive_list.html#ref.directive.list
> that there is "item_index" and "item_has_next" to handle dynamic length
> lists, i.e. the "vertical" of the table.
> I guess, I could convert the "flower" data structure into a sequence again,
> then, it would be possible to create an inner loop... and thus handle the
> "horizontal" of the table...
>
> Basically I want to create one cvs to sql-insert statement macro that I can
> use for any csv. I think it is not too hard to get the headers right with
> the
>    <#list flowers.headers as h>
> approach, however, I would need a hint how to do the same on each row's
> content?

I don't understand... the columns are the same for each row, so it
doesn't make sense to get the headers for an individual row of a CVS
file. No?

-- 
Best regards,
 Daniel Dekany


____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click