Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2007, 08:28 AM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT conditional sum calculation

Dear all,

I have a problem with XSLT calculation. Basically what I want to achieve is: to calculate the total values of ValueItem owned by at least one applicant, which means ValueItem/PercentOwned/RelatedEntityRef/@RelatedID = Party/Identifier/@UniqueID and Party/@Type = ¡®Applicant¡¯. So the total value suppose to be 98000. Please see the XML below. I can easily apply a condition within ValueItem but I really can¡¯t figure out a way to apply the condition outside ValueItem. I use XSLT 1.0. I really appreciate if anyone here can help. Thank you very much in advance.


<Application>
        <PartySegment>
            <Party Type="Applicant">
                <Identifier UniqueID="A1"/>
            </Party>
            <Party Type="Guarantor">
                <Identifier UniqueID="A2"/>
            </Party>
        </PartySegment>
        <FinancialSegment>
            <ValueItem Value="430000">
                <Identifier UniqueID="RE1"/>
                <PercentOwned>
                    <RelatedEntityRef RelatedID="A1"/>
                </PercentOwned>
                <PercentOwned>
                    <RelatedEntityRef RelatedID="A2"/>
                </PercentOwned>
            </ValueItem>
            <ValueItem Value="40000">
                <Identifier UniqueID="NR1"/>
                <PercentOwned>
                    <RelatedEntityRef RelatedID="A2"/>
                </PercentOwned>
            </ValueItem>
            <ValueItem Value="55000">
                <Identifier UniqueID="NR2"/>
                <PercentOwned>
                    <RelatedEntityRef RelatedID="A1"/>
                </PercentOwned>
            </ValueItem>
        </FinancialSegment>
    </Application>


 
Old August 3rd, 2007, 12:12 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Something like

<xsl:key name="applicant" match="Party[@Type='Applicant']"
  use="Identifier/@UniqueID"/>

then

sum(//ValueItem[key('applicant', PercentOwned/RelatedEntityRef/@RelatedID)])

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 3rd, 2007, 10:37 PM
Registered User
 
Join Date: Apr 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much Michael! Your code works. I really appreciate your help.

All the best,

Ken






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Running Sum (or Cumulative Sum) timdasa VB Databases Basics 1 August 22nd, 2006 03:12 PM
conditional xslt processing based on java array twilson997 XSLT 7 June 28th, 2006 07:32 AM
Sum of random numbers in a table with XSLT Tschuri XSLT 0 May 8th, 2005 04:14 AM
Calculation Grantm Access 3 February 16th, 2004 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.