|
Subject: [xsl] XSL : Report Grouping Problem From: "Albert Tsun" <albert.tsun@xxxxxxxxxxxx> Date: Fri, 29 Dec 2000 19:33:23 +0800 |
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 |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] RE: utf-16 encoding, Dimitre Novatchev | Thread | [xsl] change stylesheets, Christoph Jentzsch |
| [xsl] RE: utf-16 encoding, Dimitre Novatchev | Date | RE: [xsl] applying different templa, Chris Bayes |
| Month |