-----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="{(_at_)name}">
<hits>
<xsl:value-of
select="sum(ancestor::day/gv/activity[(_at_)name=current()/@name]/hits)"/>
</hits>
</activity>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="concat('
',@date,'
')" />
<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,'
')" />
</xsl:template>
</xsl:stylesheet>
Cheers,
Andreas
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list