[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting unique and sub-total problem

Subject: Re: Sorting unique and sub-total problem
From: roger.wyatt@xxxxxxxxxxxxx
Date: Fri, 4 Jun 2004 10:54:33 +0100
total in xsl
I have final got what I want... and learnt a hell of a lot in the
process...
A combination of syntax and typos held me back some what... but I crawled
forward ...

Although looking that the other postings it is clear that I am way out of
my league.  But  I still thought it was worth posting the end result....

Thanks to Wendel and Mukul for the help...

XSL IS....

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

<xsl:key name="cards" match="ITEM" use="CARD/@number" />

<xsl:template match="/">
      <xsl:for-each select="/ITEMS" >
            <xsl:call-template name="create-body" />
      </xsl:for-each>
</xsl:template>

<xsl:template name="create-body" >
      <xsl:for-each select="./ITEM[CARD/@number and
            generate-id(.) = generate-id(key('cards', CARD/@number))]" >

                  <BR/> VALUES FOR CARD: <xsl:value-of select
="CARD/@number"/>
                  <BR/> NUMBER OF ITEMS: <xsl:value-of select="count(key
('cards', CARD/@number))" />
                  <xsl:for-each select="key('cards', CARD/@number)" >
                        <BR/> Values <xsl:value-of select="AMOUNT/@amt" />
                  </xsl:for-each>
                  <BR/> TOTAL: <xsl:value-of select=" sum( key('cards',
CARD/@number)/AMOUNT/@amt )  "/>
                  <BR/>
      </xsl:for-each>
      <BR/> GRAND TOTAL: <xsl:value-of select="sum(//AMOUNT/@amt)" />
</xsl:template>
</xsl:stylesheet>


AND THE XML IS...

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>

<ITEMS>

      <ITEM item_id='1'>  <CARD number='123456789' amt='1'/>  <AMOUNT amt
='100'/>   </ITEM>
      <ITEM item_id='2'>  <CARD number='123456789' amt='2'/>  <AMOUNT amt
='200'/>  </ITEM>
      <ITEM item_id='3'>  <CARD number='987654321' amt='3'/>  <AMOUNT amt
='30'/>  </ITEM>
      <ITEM item_id='4'>  <CARD number='123456789' amt='4'/>  <AMOUNT amt
='50'/>  </ITEM>
      <ITEM item_id='5'>  <CARD number='987654321' amt='5'/>  <AMOUNT amt
='150'/>  </ITEM>
      <ITEM item_id='6'>  <CARD number='123456789' amt='6'/>  <AMOUNT amt
='250'/>  </ITEM>

</ITEMS>

WHICH GIVES ME THIS....

VALUES FOR CARD: 123456789
NUMBER OF ITEMS: 4
Values 100
Values 200
Values 50
Values 250
TOTAL: 600

VALUES FOR CARD: 987654321
NUMBER OF ITEMS: 2
Values 30
Values 150
TOTAL: 180

GRAND TOTAL: 780

***************************************
Roger Wyatt
Principal Consultant
Nomad Software Ltd.
***************************************
This e-mail (including attachments) is confidential and is intended solely
for the addressee.  Unless authorised you may not read, copy, use or store
this e-mail in any way, or permit others to do so.  If you have received it
in error, please contact Nomad Software on +44 (0) 20 7292 2400





Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.