[XSL-LIST Mailing List Archive Home]
Re: [xsl] conditional multiline output
Subject: Re: [xsl] conditional multiline output|
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 31 Jan 2007 15:03:08 +0100
Erwin Kloeck wrote:
I have a list of date elements in my xml that I want to output in
columns in a csv file.
If the same date occurs more than once, I want another line in the
and the label in the first column.
I think I should group the dates and then cicle thru and output the
line with all 1st elements in the group, then all 2nd elements in the
second line etc.
I would appreciate some pointers at how to do this.
The following is a rough guide and is one way to tackle this. I don't
consider it pretty, and for one, you have to replace '1 to 3' with '3'
as the number of grouped values (where values are equal). Somehow I
couldn't get it right with a simple predicate and xpath, it was a bit
late yesterday ;)
Of course, you can use grouping, if you find that clearer. The output is
close to what you expect. The little details I leave to you.
<xsl:value-of select="(@value, distinct-values(date/@value))"
<xsl:value-of select="for $i in 1 to 3 return
(@value, for $val in distinct-values(date/@value)
return (';', date[@value = $val][$i]/@string), ' ')"
The 'close but not close enough' output by running this against your
example input (output method is 'text'):
The last two 'BBB' should be removed by adjusting the '1 to 3', which is
now fixed. Adding a ';' at the end of each line and adding '[@count]'
for each value should be easy enough.
-- Abel Braaksma