Results 1 to 2 of 2

Thread: Totalling

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898
    Hi All,

    I have some elements which have some attributes. I'm using the following key to obtain the correct set of elements to sort and total against.

    <xsl:key name="giveSum" match="PSL_PREMIUMS_V[@UNIT_NBR &gt; 0]" use="@POLICY_ID"/>

    <xsl:variable name="getTotals" select="key('giveSum', @POLICY_ID)"/>

    with my test data getTotals holds 3 elements which is what i'd expect.

    They all have an attribute called COVERAGE_CD which I want to sort against then I want to total on an attribute called PLP_PREMIUM_AMT. I expect to get 2 lines output, but following the examples in michael kay's book p275-276 using sum doesn't seem to give me the results and I still get three seperate lines. I figured this was because it's in a for-each loop so I thought I'd do the sort and an apply templates, but I keep being told I cannot use sort in the place specified. Can anyone give me any pointers as to how I should be sorting and totaling based on the values obtained by my key.

    So if my three lines in getTotals are:

    <PSL_PREMIUMS_V COVERAGE_CD="QAS" PLP_PREMIUM_AMT="10.00" ......
    <PSL_PREMIUMS_V COVERAGE_CD="APL" PLP_PREMIUM_AMT="10.00" ......
    <PSL_PREMIUMS_V COVERAGE_CD="QAS" PLP_PREMIUM_AMT="12.00" ......

    I want to end up with
    <TOTAL COVERAGE_CD="QAS" VALUE="22.00">
    <TOTAL COVERAGE_CD="APL" VALUE="10.00">

    I know that if I use :
    <xsl:sort select="@COVERAGE_CD"/>
    this will group the details correctly.

    Regards
    Bill Crawley

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898
    Hi To all though's that are interested. I've managed to crack this little nasty.

    Here's the code (it's only taken me 3 days)

    <xsl:variable name="getTotals" select="key('giveSum', @POLICY_ID)"/>
    <xsl:element name="Total">
    <!-- <xsl:for-each select="self::*[not($getTotals/@COVERAGE_CD=preceding-sibling::COVERAGE_CD)]"><xsl:sort select="$getTotals/@COVERAGE_CD"/>
    <xsl:attribute name="{$getTotals/@COVERAGE_CD}"> <xsl:value-of select="sum($getTotals/@PLP_PREMIUM_AMT)"/></xsl:attribute>
    </xsl:for-each> -->
    <xsl:for-each select="$getTotals">
    <xsl:sort select="@COVERAGE_CD"/><xsl:attribute name="{@COVERAGE_CD}">
    <xsl:value-of select="sum(preceding-sibling::*[not(@COVERAGE_CD=preceding-sibling::COVERAGE_CD)]/@PLP_PREMIUM_AMT)"/></xsl:attribute>
    </xsl:for-each>
    </xsl:element>

    Horid I know copy it into notepad and it'll be more readable.

    Cheers
    Bill Crawley

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width