Re: [xsl] job for xsl:key? (XSL 1.0 question)

Subject: Re: [xsl] job for xsl:key? (XSL 1.0 question)
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 20 Feb 2007 15:47:22 +0000
On 2/20/07, Steve <stephen@xxxxxxxxx> wrote:
I could do the following easily by making a recursive template and
then looping through the contacts, and passing on the corresponding
benchmark value.  But could xsl:key make for a shorter, more elegant

Instead of performing an addition for each <contact>, could I simply
sum() them at once, somehow?

With the following XML

    <type value="1" benchmark1="540" />
    <type value="2" benchmark1="640" />
    <type value="3" benchmark1="740" />
    <contact type="1" />
    <contact type="2" />
    <contact type="3" />
    <contact type="3" />

desired output:

    <benchmark val='2660'  />

No need for key() here, an XPath will be fine:

<xsl:template match="contact">
   <benchmark val="{sum(//type[@value =

You'll need to adjust the path to <type> according to your XML.


Current Thread