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

Re: Using xsl:key to list unique nested values

Subject: Re: Using xsl:key to list unique nested values
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Tue, 08 Jan 2002 09:34:03 -0500
xslt key nested
At 2002-01-08 12:46 +1100, Trem Stamp wrote:
I can get the listing of Unique customers

Customer 1
      Project 1
      Project 2
      Project 1

Customer 2
      Project 1
      Project 1

However I'm unsure as to how to only list the unique Projects within these
listings.  I've checked the archives and Dawsons (but couldn't find anything

Try doing only localized grouping with variables (solution below). You'll see that I am only grouping the projects on the collection of records for each customer.

I hope this helps.

................... Ken

t:\ftemp>type stamp.xml <PROJECTS> <PROROW> <id>1</id> <name>Customer 1</name> <project_name>Project 1</project_name> </PROROW> <PROROW> <id>2</id> <name>Customer 1</name> <project_name>Project 2</project_name> </PROROW> <PROROW> <id>3</id> <name>Customer 2</name> <project_name>Project 1</project_name> </PROROW> <PROROW> <id>3</id> <name>Customer 2</name> <project_name>Project 4</project_name> </PROROW> <PROROW> <id>3</id> <name>Customer 1</name> <project_name>Project 1</project_name> </PROROW> </PROJECTS>

t:\ftemp>type stamp.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:output method="text"/>

<xsl:template match="/">
  <xsl:variable name="prorows" select="/*/PROROW"/>
  <xsl:for-each select="$prorows">
    <xsl:if test="generate-id(.)=
      <xsl:value-of select="name"/>:
      <xsl:variable name="custs" select="$prorows[name=current()/name]"/>
      <xsl:for-each select="$custs">
        <xsl:if test="generate-id(.)=
          <xsl:text>    </xsl:text>
          <xsl:value-of select="project_name"/>


t:\ftemp>xt stamp.xml stamp.xsl stamp.txt

t:\ftemp>type stamp.txt
Customer 1:
    Project 1
    Project 2
Customer 2:
    Project 1
    Project 4


-- Training Blitz: 3-days XSLT/XPath, 2-days XSLFO - Feb 18-22, 2002

G. Ken Holman                mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.         http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995)
ISBN 0-13-065196-6                        Definitive XSLT & XPath
ISBN 1-894049-08-X  Practical Transformation Using XSLT and XPath
ISBN 1-894049-07-1               Practical Formatting Using XSLFO
XSL/XML/DSSSL/SGML/OmniMark services, books(electronic, printed),
articles, training(instructor-live,Internet-live,web/CD,licensed)
Next public training:   2002-01-10,11,16,18,02-11,12,13,15,18,21,
-                                03-11,14,15,18,19,04-08,09,10,12

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

Current Thread


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.
First Name
Last Name
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.