Re: [xsl] XSL Query

Subject: Re: [xsl] XSL Query
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Sun, 27 Oct 2002 08:31:57 +0000
Hello Navin,

to make it short: It's a grouping problem and there is a nice technique called Muenchian Grouping (

The key you already got correctly:

<xsl:key name="locations" match="location" use="@country"/>

<xsl:template match="/">
<xsl:apply-templates select="//location[generate-id() = generate-id(key('locations', @country))]" mode="unique"/>

<xsl:template match="location" mode="unique">
<xsl:value-of select="@country"/>: <xsl:value-of select="sum(key('locations', @country)/sales)"/>



Mulberry Technologies List Owner wrote:
Date: Sat, 26 Oct 2002 19:51:51 -0400
From: Navin Kumar <navin1@xxxxxxxx>
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject: Need help on XSL query


I need to display the sum of sales for each country only once! Current code is
not properly working and I understand it is because the loop itself is to
select all possible "@country" occurences but I also tried to use set:distinct
but am getting error like "set function not found in namespace...". Could
someone help me out in resolving this problem?  Here is the template I have

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"

<xsl:key name="locations" match="location" use="@country" />
<xsl:template match="/">
	<xsl:for-each select="//@country">
	<xsl:variable name="country">
		<xsl:value-of select="." />
	<xsl:variable name="Total">
		<xsl:value-of select="sum(key('locations',$country)/sales)" />
	<xsl:value-of select="$country" />
	<xsl:value-of select="$Total" />	<br/>

 <time year="1996" quarter="1">
	<product category="Ford" brand="Escort">
		<location country="USA" state="NY">
		<location country="USA" state="CA">
		<location country="Canada" state="Ontario">
		<location country="Canada" state="British Columbia">

Thanks and regards,

XSL-List info and archive:

Current Thread