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

RE: RE: Sum & Sort & Maxvalue

Subject: RE: RE: Sum & Sort & Maxvalue
From: "Andreas L. Delmelle" <a_l.delmelle@xxxxxxxxxx>
Date: Tue, 9 Mar 2004 18:02:42 +0100
sort sum
> -----Original Message-----
> From: Florian Mueller
>
> Thank you very much for your answer. Theres only a little Problem
> left: I dont understand anything. :) Maybe you could send me a
> File where you put in the complete solution.. I have no idea what
> i should do..
>

Hi Flo,

No problem. Just c&p the files below. The method being used is yet another
variant of Muenchian grouping, should you have encountered that term
already..


Your source xml, slightly modified to contain a root

<?xml version="1.0" encoding="UTF-8" ?>
<root>
<day date="01.03.2004">
   <users>1</users>
   <gv name="Offerte Neu">
      <hits>2</hits>
      <activity name="Ermittlung eines Produktes">
         <hits>2</hits>
      </activity>
   </gv>
   <gv name="SimulatorWeb">
      <hits>1</hits>
      <activity name="SimulatorDummy">
         <hits>1</hits>
      </activity>
      <activity name="Ermittlung eines Produktes">
         <hits>3</hits>
      </activity>
   </gv>
   <gv name="CIS">
      <hits>1</hits>
      <activity name="Vertrags Anzeige">
         <hits>1</hits>
      </activity>
      <activity name="Vertrags Suche">
         <hits>1</hits>
      </activity>
   </gv>
   <gv name="Muster">
      <hits>11</hits>
      <activity name="Muster">
         <hits>11</hits>
      </activity>
   </gv>
   <gv name="Mahninfo">
      <hits>1</hits>
      <activity name="Mahninfo">
         <hits>1</hits>
      </activity>
   </gv>
</day>
<day date="02.03.2004">
   <users>2</users>
   <gv name="Offerte Neu">
      <hits>3</hits>
      <activity name="Erfassung Produktedaten">
         <hits>1</hits>
      </activity>
      <activity name="Ermittlung eines Produktes">
         <hits>3</hits>
      </activity>
   </gv>
   <gv name="Mahninfo">
      <hits>3</hits>
      <activity name="Mahninfo">
         <hits>3</hits>
      </activity>
   </gv>
</day>
</root>


The XSL solution I propose:

<?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ext="http://exslt.org/common"
        extension-element-prefixes="ext" />

<!-- key to approach activities by day and activity-name -->
<xsl:key name="acts-day-name" match="activity"
         use="concat(ancestor::day/@date,@name)" />

<xsl:template match="root">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="day">
  <!-- variable containing all distinct activity names
       for the day being processed -->
  <xsl:variable name="vacthelp"
         select="gv/activity[generate-id(.)=
           generate-id(
             key('acts-day-name', concat(
               current()/@date, @name)
                )[1])]" />

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

  <xsl:value-of select="concat('&#x0A;',@date,'&#x0A;')" />
  <xsl:apply-templates select="ext:node-set($vacts)/*">
    <xsl:sort select="hits" data-type="number" order=descending" />
  </xsl:apply-templates>

</xsl:template>

<xsl:template match="activity">
  <xsl:value-of select="concat(.,' : ', hits,'&#x0A;')" />
</xsl:template>

</xsl:stylesheet>


Cheers,

Andreas


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


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.