xsl-list
[Top] [All Lists]

Re: [xsl] conditional multiline output

2007-01-31 08:38:31
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
respective column
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.

Hi Erwin,

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:template match="logpoint">
<xsl:value-of select="(@value, distinct-values(date/@value))" separator=";"/>
       <xsl:text>&#10;</xsl:text>
       <xsl:value-of select="for $i in 1 to 3 return
           (@value, for $val in distinct-values(date/@value)
return (';', date[(_at_)value = $val][$i]/@string), '&#10;')" separator="" />
       <xsl:text>&#10;</xsl:text>
   </xsl:template>

The 'close but not close enough' output by running this against your example input (output method is 'text'):

AAA;2007-01-01;2007-01-02;2007-01-03;2007-01-04
AAA;aaa;bbb;ccc;eee
AAA;xxx;;ddd;
AAA;;;yyy;

BBB;2007-01-01;2007-01-02;2007-01-03;2007-01-04
BBB;lll;mmm;nnn;ooo
BBB;;;;
BBB;;;;

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 '[(_at_)count]' for each value should be easy enough.

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>