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

XSL : Report Grouping Problem

Subject: XSL : Report Grouping Problem
From: "Albert Tsun" <albert.tsun@xxxxxxxxxxxx>
Date: Fri, 29 Dec 2000 19:33:23 +0800
xsl report

Dear All XSL expert,

I hava a input xml data source which I need to format it to a nicely
grouped report.
I am using xalan to do the XSLT.

I have to do the grouping by Service, then ExCode+ExName, then Date+CCY.
In my first sight, I use several for-loop in my XSL to do this.
First loop all the distinct Service node and
      then loop all distinct Item[ExCode+ExName] and
          then loop all distinct Item[Date+CCY} and
               then loop all item[Service+(ExCode+ExName)+(Date+CCY)]
+++++++++++
XML Source:
+++++++++++
<Data>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>A</Ref>
          <Date>20001221</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>B</Ref>
          <Date>20001221</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>C</Ref>
          <Date>20001222</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>D</Ref>
          <Date>20001222</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>E</Ref>
          <Date>20001222</Date>
          <CCY>USD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>A</ExCode>
          <ExName>Exchange A</ExName>
          <Ref>F</Ref>
          <Date>20001222</Date>
          <CCY>USD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>B</ExCode>
          <ExName>Exchange B</ExName>
          <Ref>G</Ref>
          <Date>20001222</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>M</Service>
          <ExCode>B</ExCode>
          <ExName>Exchange B</ExName>
          <Ref>H</Ref>
          <Date>20001222</Date>
          <CCY>HKD</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>C</Service>
          <ExCode>C</ExCode>
          <ExName>Exchange C</ExName>
          <Ref>I</Ref>
          <Date>20001230</Date>
          <CCY>YEN</CCY>
          <Amt>1000.00</Amt>
     </Item>
     <Item>
          <Service>C</Service>
          <ExCode>C</ExCode>
          <ExName>Exchange C</ExName>
          <Ref>J</Ref>
          <Date>20001230</Date>
          <CCY>YEN</CCY>
          <Amt>1000.00</Amt>
     </Item>
</Data>
+++++++++++++++
Expected Ouput :
+++++++++++++++
          Date      Ref  Currency  Amount
==================================================================
Service Type : M
     Exchange Code & Desc : A , Exchange A
          20001221            A    HKD                      1000.00
          20001221            B    HKD                      1000.00

          20001222           C     HKD                      1000.00
          20001222           D     HKD                      1000.00

          20001222            E    USD                      1000.00
          20001222            F    USD                      1000.00

     Exchange Code & Desc : B , Exchange B
          20001221          G  HKD                      1000.00
          20001221           H      HKD                      1000.00

Service Type : C
     Exchange Code & Desc :C , Exchange C
          20001230       I          YEN                      1000.00
          20001230       J          YEN                     1000.00

+++++++++++++++
my XSL scriplet
+++++++++++++++
<xsl:variable name="dist_service"
select="//Service[not(.=preceding::Service]"/>
<xsl:key name="exchange" match="Data use="concat(ExCode, ' ',ExName)"/>
<xsl:key name="date_ccy" match="Data" use="concat(CCY, ' ',Date)"/>

<xsl:template match="Data">
     <xsl:for-each select="$dist_service">
          <xsl:variable name="this_service" select="."/>
          <xsl:value-of select="$this_service"/>
          <xsl:for-each
select="//Item[count(key("exchange",concat(ExCode,'',ExName))[1] | . )=1]">
<<--- is there way I can select distinct "exchange" with
Service=$this_service?
               <xsl:variable name="this_excode" select="ExCode"/>
               <xsl:variable name="this_exname" select="ExName"/>
               <xsl:value-of select="$this_excode"/>
               <xsl:value-of select="$this_exname"/>
               <xsl:for-each
select="//Item[count(key("date_ccy",concat(CCY,'',Date))[1] | . )=1]">
                    <xsl:variable name="this_ccy" select="CCY"/>
                    <xsl:variable name="this_date" select="Date"/>
                    <xsl:for-each select="//Item[Service=$this_service and
ExCode=$this_excode and ExName=this_exname and CCY=$ths_ccy and
Date=$this_date]">
                         <xsl:value-of select="Date">
                         <xsl:value-of select="Ref">
                         <xsl:value-of select="CCY">
                         <xsl:value-of select="Amt">
                    </xsl:for-each>
               </xsl:for-each>
          </xsl:for-each>
     </xsl:for-each>
</xsl:template>

?????? However what I got is
     Service Type M
               A, Exchange A
                    ...  .....     ....
               B, Exchange B
                    .... .....          ......
               C, Exchange C  <<<<<--- I do not want this

     Service Type C
               A, Exchange A  <<<<<--- I do not want this
               B, Exchange B  <<<<<--- I do not want this
               C, Exchange C
                    .....   ........ ....................

Would someone please help to correct my xsl please ?

Many Thanks.




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.