Multi Column Row Woes
By Tim Dexter on Dec 05, 2007
Through streaming eyes and a nose that wont stop running, its a doozy of a cold/flu. I found a nice question yesterday on the forum from Chris (chrish6):
I have just spent the last couple of hours trying to do something which I was hoping would be fairly simple - the only thing I have figured out is that it is not simple.
Heres my problem, I have data structured like so
I want the data to come out in RTF data like this
Chris One Chris Two
Chris Three Chris Four
I really want to avoid changing the data file.
So I don't come across as a lazy boy I have looked into a couple of things....
Tims blog on Rows and Columns - this is the direction I need to go but I don't get how to force a new line - I tried it and got all records on one line.
I've read various forum posts a blog by another guy doing invoice stuff - which seems over complicated for what I need.
Tim - any chance you could do a follow up to your rows and columns blog??
I'm running latest BIP,
my data can have x amount of records and may be an odd or even amount of records.
Not sure on the horse reference, maybe Chris has a race horse stable and wants to generate address labels for them. I came up with a solution that requires you to specify the number of columns you want in the table. In Chris' case its 2, it relies on a small piece of XPATH code to get specific records or horses to show up.
All we have in the template is a 2 celled table, inside each we have a complete for-each loop with the HORSE_NAME and an end loop.
The contents of the F fields are :
<?for-each:HORSE[position() mod 2=1]?> - <?for-each:HORSE[position() mod 2=0]?>
the [position() mod 2 =1] expression tests the result of dividing the current record number by two and check the remainder. This puts the odd records into the first column and even records into the second column.
Now your not tied to two columns, just add a column and adjust the 'mod' calculation to have
<?for-each:HORSE[position() mod 3=1]?>
- <?for-each:HORSE[position() mod 3=2]?>
- <?for-each:HORSE[position() mod 3=0]?>
to get this output
Sample template and data here.
You can keep going as long as you wish, just need to work out the 'mod' calcs and of course if you dont want horses but maybe address labels, just add the fields you need and you're 'off the races' as it were.