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

Re: XSL Query

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

to make it short: It's a grouping problem and there is a nice technique called Muenchian Grouping (http://www.jenitennison.com/xslt/grouping/muenchian.xml).

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>


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


Regards,

Joerg


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

Hello,

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
written:

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

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

XML FILE IS
===========
<SalesDB>
 <time year="1996" quarter="1">
	<product category="Ford" brand="Escort">
		<location country="USA" state="NY">
			<sales>70</sales>
		</location>
		<location country="USA" state="CA">
			<sales>80</sales>
		</location>
		<location country="Canada" state="Ontario">
			<sales>90</sales>
		</location>
		<location country="Canada" state="British Columbia">
			<sales>100</sales>
		</location>
	</product>
      .........continue........
===============================================

Thanks and regards,
Navin


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.