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

Re: Grouping elements and summing their attribute valu

Subject: Re: Grouping elements and summing their attribute value into one single element
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 24 Mar 2005 11:14:27 GMT
xml sum
Just use the usua; grouping techniques (eg keys as below) to group, and
then use sum() to sum all elements of a group.

eg


<?xml version="1.0" encoding="iso-8859-1"?>
<EintrdgeListe>
	<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0811" BZ_DLA="B1" BZ_Format="NF" BZ_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit="1442" BZF_Zustelldatum="20050211" BZF_MengeGezdhlt="58"/>
	<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0835" BZ_DLA="B1" BZ_Format="NF" BZ_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit="1442" BZF_Zustelldatum="20050211" BZF_MengeGezdhlt="47"/>
	<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0847" BZ_DLA="B1" BZ_Format="NF" BZ_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit="1442" BZF_Zustelldatum="20050211" BZF_MengeGezdhlt="42"/>
...
	<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0947" BZ_DLA="B1" BZ_Format="NF" BZ_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit="1442" BZF_Zustelldatum="20050211" BZF_MengeGezdhlt="42"/>
</EintrdgeListe>






<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:om="http://www.openmath.org/OpenMath"
                version="1.0">

<xsl:output indent="yes"/>

<xsl:key name="e" match="Eintrag" use="substring(@BZ_Zeit,1,2)"/>

<xsl:template match="EintrdgeListe">
<xsl:for-each select="Eintrag[generate-id()=generate-id(key('e',substring(@BZ_Zeit,1,2)))]">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:attribute name="BZ_Zeit"><xsl:value-of select="substring(@BZ_Zeit,1,2)"/>00</xsl:attribute>
<xsl:attribute name="BZF_MengeGezdhlt"><xsl:value-of select="sum(key('e',substring(@BZ_Zeit,1,2))/@BZF_MengeGezdhlt)"/></xsl:attribute>
</xsl:copy>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>




$ saxon  sum.xml sum.xsl
<?xml version="1.0" encoding="utf-8"?>
<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0800" BZ_DLA="B1" BZ_Format="NF" B
_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit
"1442" BZF_Zustelldatum="20050211" BZF_MengeGez@qhlt="147"/>
<Eintrag BZ_Abgangsdatum="20050211" BZ_Zeit="0900" BZ_DLA="B1" BZ_Format="NF" B
_Verarbeitung="Maschine" BZ_Bundart="999" BZF_Ankunftsdatum="20050211" BZF_Zeit
"1442" BZF_Zustelldatum="20050211" BZF_MengeGez@qhlt="42"/>

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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.