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

conditional multiline output

Subject: conditional multiline output
From: "Erwin Kloeck" <kloeck@xxxxxxxxx>
Date: Tue, 6 Feb 2007 10:44:30 +0100
 conditional multiline output
Hi,

A week ago a posted the following problem and Abel Braaksma was kind enough to
to give it some consideration.

I have in the meantime come up with a solution and would like to
solicit your comments
on how to make it more simple and clear. There is a real question here
as well: Where
does the space in front of the closing bracket come from and how do I
get rid of it?

Thanks

Erwin

Here is my solution (I omitted the header line) and I appended my
original problem:

--- begin example.xsl ---
<?xml version="1.0" encoding="UTF-8"?>
<?altova_samplexml C:\workspaces\tmp\xsl\example.xml?>
<xsl:stylesheet version="2.0"
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
               xmlns:fn="http://www.w3.org/2005/xpath-functions"
               xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:output method="text" version="1.0" encoding="iso-8859-1"/>

   <xsl:variable name="delimiter" select="'; '" />
   <xsl:variable name="newline" select="'&#10;'" />

   <xsl:template match="/">
       <xsl:apply-templates/>
   </xsl:template>

<xsl:template match="logpoint">

       <xsl:variable name="this" select="." />
       <xsl:variable name="dates" select="distinct-values(date/@value)" />

       <xsl:variable name="max-count" >
           <xsl:value-of select="max(for $date in $dates return
count(date[@value = $date]))" />
       </xsl:variable>

       <xsl:for-each select="(1 to $max-count)" >
           <xsl:variable name="i" select="." />
           <xsl:value-of select="$this/@value" />
           <xsl:value-of select="$delimiter" />
           <xsl:for-each-group select="$this/date" group-by="@value" >
               <xsl:if test="current-group()[$i]/@string" >
                   <xsl:value-of
select="concat(current-group()[$i]/@string, ' [',
current-group()[$i]/@count), ']'" />
               </xsl:if>
               <xsl:value-of select="$delimiter" />
           </xsl:for-each-group>

           <xsl:value-of select="$newline" />
       </xsl:for-each>
   </xsl:template>
</xsl:stylesheet>
--- end example.xsl ---


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.



--- begin example.xml --- <?xml version="1.0" encoding="UTF-8"?> <top> <logpoint value="AAA" > <date value="2007-01-01" count="1" string="aaa"/> <date value="2007-01-01" count="11" string="xxx"/> <date value="2007-01-02" count="2" string="bbb"/> <date value="2007-01-03" count="3" string="ccc"/> <date value="2007-01-03" count="4" string="ddd"/> <date value="2007-01-03" count="41" string="yyy"/> <date value="2007-01-04" count="5" string="eee"/> </logpoint> <logpoint value="BBB" > <date value="2007-01-01" count="31" string="lll"/> <date value="2007-01-02" count="32" string="mmm"/> <date value="2007-01-03" count="33" string="nnn"/> <date value="2007-01-04" count="34" string="ooo"/> </logpoint> </top> --- begin example.xml ---


desired output: --- begin example.csv --- logpoint;2007-01-01;2007-01-02;2007-01-03;2007-01-04; AAA;aaa[1];bbb[2];ccc[3];eee[5]; AAA;xxx[11];;ddd[4];; AAA;;;yyy[41];; BBB;lll[31];mmm[32];nnn[33];ooo[34]; --- end example.csv ---

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-2013 All Rights Reserved.