<kakridge(_at_)bellsouth(_dot_)net> wrote in message
news:007d01c3c442$d52eb700$02fea8c0(_at_)XP1700(_dot_)(_dot_)(_dot_)
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,
':	',
sum(key('kAccByNum',
GLAccountNumber
)/Amount
),
'
'
)"/>
</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 < 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