xsl-list
[Top] [All Lists]

RE: Sum & Sort & Maxvalue

2004-03-06 09:46:30
-----Original Message-----
From: Florian Mueller

I have a complex problem. I dont know if i can explain it correctly.


Hi,

Given your input XML, the following

<xsl:key name="acts-day-name" match="activity"
         use="concat(ancestor::day/@date,@name)" />

will give you a handle to the unique activity names for a given day when
used in combination with a template like

<xsl:template match="day">
  <xsl:variable name="vacthelp"
         select="gv/activity[generate-id(.)=
           generate-id(
             key('acts-day-name', concat(
               current()/@date, @name)
                )[1])]" />
  ...
</xsl:template>

The trick then seems to be to construct a variable like

<xsl:variable name="vacts">
  <xsl:for-each select="$vacthelp">
    <activity name="{(_at_)name}">
      <hits><xsl:value-of
select="sum(ancestor::day/gv/activity[(_at_)name=current()/@name]/hits)"
/></hits>
    </act>
  </xsl:for-each>
</xsl:variable>

Then apply-templates, using the node-set extension function

<xsl:apply-templates select="ext:node-set($vacts)" />

I have been trying this with a sort on the hits-node, but it didn't seem to
be working. Just posting already since it seems that mainly the summing was
bothering you up to here, and in this way at least, I got the numbers
right..


Hope this helps!

Cheers,

Andreas


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



<Prev in Thread] Current Thread [Next in Thread>