[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: conditional multiline output

Subject: Re: conditional multiline output
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 31 Jan 2007 15:03:08 +0100
Re:  conditional multiline output
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[@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 '[@count]' for each value should be easy enough.

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.