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

Using xsl:key to list unique nested values

Subject: Using xsl:key to list unique nested values
From: "Trem Stamp" <trem@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 8 Jan 2002 12:46:57 +1100
xsl key unique
Hi all,

I have an xml file with duplications of elements, which I can list uniquely
fine (used the XSL example by Jenni Tennison).

The xml file looks like this:

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

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
obvious).

I've been trying to use another: <xsl:apply-templates
select="../PROROW[generate-id(.) = generate-id(key('rows', project_name))]"
mode="again"/> line within the first template that lists the customers, but
this provides a listing of all unique Projects for each customer under each
customer heading.

The stylesheet I have used is:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="rows" match="PROROW" use="name"/>
<xsl:key name="rows" match="PROROW" use="project_name"/>

<xsl:template match="PROJECTS">
  <xsl:apply-templates select="PROROW[generate-id(.) =
generate-id(key('rows', name)[1])]" mode="other"/>
</xsl:template>
<xsl:template match="PROROW" mode="other">
  <b><xsl:value-of select="name" /></b>
    <xsl:apply-templates select="../PROROW[generate-id(.) =
generate-id(key('rows', project_name))]" mode="again"/>
</xsl:template>
<xsl:template match="PROROW" mode="again">
  <xsl:value-of select="project_name" />
</xsl:template>
</xsl:stylesheet>

I would be very grateful if someone could pointme in the direction of a
working example of this in action.

Trem


 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.