XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Rahul VaidSubject: How to show summation based on certan conditions
Author: Rahul Vaid
Date: 06 Feb 2006 05:48 AM
Now, Iam having the XML data as follows:

<trades >
<row>
<valueDate>2006-02-08</valueDate>
<contractCurrency>AUD</contractCurrency>
<contractAmount>-5000</contractAmount>
</row>
<row>
<valueDate>2006-02-09</valueDate>
<contractCurrency>GBP</contractCurrency>
<contractAmount>-5000</contractAmount>
</row>
<row>
<valueDate>2006-02-08</valueDate>
<contractCurrency>AUD</contractCurrency>
<contractAmount>10000</contractAmount>
</row>
<row>
<valueDate>2006-02-08</valueDate>
<contractCurrency>GBP</contractCurrency>
<contractAmount>-5000</contractAmount>
</row>
<row>
<valueDate>2006-02-09</valueDate>
<contractCurrency>GBP</contractCurrency>
<contractAmount>-5000</contractAmount>
</row>
</trades>

Iam required to display the data as follows:

AUD GBP USD CHF
2006-02-08
(Summation of all
the contractAmount
where contractCurrency
is AUD and value
date is 08-02-2006)

2006-02-09
2006-02-06

But these dates are not known to me in the beginning ie the dates can only be obtained at runtime.
So I cant hardcode the dates.
So the output for the above case should be as follows:


AUD GBP USD CHF
2006-02-08 5000 -5000
2006-02-09 -10000
2006-02-12

Can anyone suggest me as to how to go about this.

Thanx in advance.
Rahul.


Postnext
(Deleted User) Subject: How to show summation based on certan conditions
Author: (Deleted User)
Date: 06 Feb 2006 10:41 AM
Hi, Rahul.

You can use XSLT grouping to do this. At a high level, what you want to do is group on the <valueDate> element, and then loop through those groups and use the sum function to sum <contractAmount> based on <contractCurrency>.

You'll find lots of examples of XSLT grouping by searching SSDN. This topic might be a good place to start:

http://www.stylusstudio.com/SSDN/default.asp?action=9&read=4021&fid=48

David Foster
Stylus Studio Team

Postnext
Rahul VaidSubject: How to show summation based on certan conditions
Author: Rahul Vaid
Date: 07 Feb 2006 04:37 AM
Hi,
Thanx for the instant reply that you normally give.I was able to solve the problem using the example you had given but still Iam not able to group them up on contractcurrency

Following is the cod ethat I have currently written:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="group" match="row" use="maturityDate"/>

<xsl:template match="/">
<table>
<xsl:for-each select="//row[generate-id() = generate-id(key('group', maturityDate)[1])]">

<tr>
<td>
<xsl:value-of select="maturityDate"/>
</td>


<xsl:choose>
<xsl:when test= "contractCurrency ='EUR'">
<td>
<xsl:value-of select="concat(sum(key('group',
maturityDate)/contractAmount), ' ')"/>
</td>
</xsl:when>
<xsl:when test= "contractCurrency='AUD'">
<td>
BBB
</td>
</xsl:when>
<xsl:when test= "contractCurrency='USD'">
<td>
CCC
</td>
</xsl:when>
<xsl:otherwise>
<td>
</td>
</xsl:otherwise>
</xsl:choose>


</tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>


But the output that Iam getting is just as below:


2006-02-08 -150000
2006-02-07 -10000


Please help me out with this problem.
Thanx in advance.
Rahul.

Postnext
Rahul VaidSubject: How to show summation based on certan conditions
Author: Rahul Vaid
Date: 07 Feb 2006 06:29 AM
To solve the problem of summing up on contract currency I even used the sum in two different ways as follows, But Iam still unaware of how to use the the filtering on contractcurrency.


<xsl:value-of select="current()/contractAmount +sum(following-sibling::row[maturityDate = current()/maturityDate]/contractAmount)"/>


OR

<xsl:value-of select="concat(sum(key('group',maturityDate)/contractAmount), ' ')"/>

Please help me out with this.

Thanx in advance.
Rahul.

Posttop
(Deleted User) Subject: How to show summation based on certan conditions
Author: (Deleted User)
Date: 07 Feb 2006 05:37 PM
Hi, Rahul. Attached is a solution that should provide what you are looking for. One thing to note is that it uses a key (formed by concatenating valueDate and contractCurrency) in order to identify unique occurrences on which to perform the sum function.

We offer free support for Stylus Studio on this site (since this is the Stylus Studio Developer Network), but if this is a generic XSLT question, you might want to consider asking it on the xsl-list mailing list, which specializes in general-purpose XSLT issues. Here is just one resource to consider:

http://www.mulberrytech.com/xsl/xsl-list/

David Foster
Stylus Studio Team


Documentcurrency_concat.xsl

 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.