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

Re: Selecting unique elements

Subject: Re: Selecting unique elements
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Thu, 9 Nov 2000 15:19:38 -0800
xsl unique selection
| I'm building a transform for a saved ADO recordset and I need to select
| unique values. I thought that I could use 
| 
| //row[preceding-sibling::row/attribute::UserName !=
| attribute::UserName]/attribute::UserName
| 
| It didn't work (well, it didn't return an error, it just didn't result in
| anything useful so either the current version of MSMXL doesn't have these
| features or I'm missed some important point.
| 
| any suggestions?


You can use <xsl:key>'s to do this unique selection.
MSXSL 3.0 production release supports this, as does
Oracle XSLT, Saxon, and Xalan, among others perhaps.

Here's a stylesheet that produces a list of unique
user names for your XML input...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">

   <xsl:output indent="yes"/>

   <!-- Index rows based on their Username attribute -->
   <xsl:key name="k" match="z:row" use="@UserName"/>

 <xsl:template match="/">
   <Users>

     <!-- Select rows which *first* mention each unique username -->
     <xsl:for-each select="/rs:data/z:row[generate-id(.)=generate-id(key('k',@UserName)[1])]">
      <Name><xsl:value-of select="@UserName"/></Name>
     </xsl:for-each>
   </Users>
 </xsl:template>

</xsl:stylesheet>

This produces:

<Users>
   <Name>bar</Name>
   <Name>foo</Name>
   <Name>system</Name>
</Users>
______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/





 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.