[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Re: Sum a group of transactions, and determne debit or credit


Subject: [xsl] Re: Sum a group of transactions, and determne debit or credit
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Wed, 17 Dec 2003 07:45:39 +0100

<kakridge@xxxxxxxxxxxxx> wrote in message
news:007d01c3c442$d52eb700$02fea8c0@xxxxxxxxx
> I've looked countless places for this answer, so I thought I'd throw it
> out to the experts.  I truly appreciate any advice.  I basically have a
> listing of transaction that are unsorted.  I need to sort by an account
> code, then give a total of debits and credits on each account code, then
> a final total of debits in credits.  Right now, I am able to break
> between each account code, but I'm having trouble summating the totals.

This is a good case to apply the Muenchian method for grouping.

When this transformation:

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

  <xsl:output method="text"/>

  <xsl:key name="kAccByNum" match="AccountLineItem"
   use="GLAccountNumber"/>

  <xsl:template match="/">
    <xsl:for-each
    select="/*/*[generate-id()
                =
                 generate-id(key('kAccByNum',
                                 GLAccountNumber
                                 )[1]
                             )
                 ]">
      <xsl:value-of
       select="concat(GLAccountNumber,
                     ':&#09;',
                      sum(key('kAccByNum',
                               GLAccountNumber
                              )/Amount
                          ),
                      '&#xA;'
                      )"/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

is applied on this source.xml:

<ArrayOfAccountLineItem xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <AccountLineItem>
        <Name>Base Price</Name>
       <Amount>90</Amount>
       <GLAccountNumber>P3-325-23114-5223-33181</GLAccountNumber>
  </AccountLineItem>
  <AccountLineItem>
        <Name>Base Price</Name>
       <Amount>-30</Amount>
       <GLAccountNumber>P3-325-23114-5223-33181</GLAccountNumber>
  </AccountLineItem>
  <AccountLineItem>
       <Name>Base Price</Name>
       <Amount>20</Amount>
       <GLAccountNumber>P3-325-23114-5246-33181</GLAccountNumber>
  </AccountLineItem>
  <AccountLineItem>
       <Name>Base Price</Name>
       <Amount>10</Amount>
       <GLAccountNumber>P3-325-23114-5246-33181</GLAccountNumber>
  </AccountLineItem>
  <AccountLineItem>
       <Name>Equipment Rental Price if Age &lt; 18</Name>
       <Amount>9</Amount>
       <GLAccountNumber>P3-325-23114-5408-33181</GLAccountNumber>
  </AccountLineItem>
  <AccountLineItem>
       <Name> Resident Discount</Name>
       <Amount>-5</Amount>
       <GLAccountNumber>P3-325-23114-5500-33181</GLAccountNumber>
  </AccountLineItem>
</ArrayOfAccountLineItem>


the wanted result is produced:

P3-325-23114-5223-33181: 60
P3-325-23114-5246-33181: 30
P3-325-23114-5408-33181: 9
P3-325-23114-5500-33181: -5



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

Resume:
http://fxsl.sourceforge.net/DNovatchev/Resume/Res.html




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



Current Thread