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

Re: adding unique values to a drop-down list

Subject: Re: adding unique values to a drop-down list
From: "Thomas B. Passin" <tpassin@xxxxxxxxxxxx>
Date: Tue, 4 Dec 2001 16:44:09 -0500
xsl unique list
[Katie McNally]

> I have not been able to correctly fill the drop-down with brokers.  The
> drop-down must contain the broker name/id combinations listed
alphabetically
> with no duplicates.
>
>

The suggestion you were trying out contained

<xsl:for-each select="Loan[not(.=preceding-sibling::*)

This would prevent unique entries if the items were sorted, but I'm not
clear they are.  There is at least one standard way to get a unique list,
using keys - it's in the various FAQs.  You have create a key that returns
the items.  Then you  set a variable equal to what the key returns,,
provided it is the first if there are any duplicates,  and then you have a
unique list.

This approach does not depend on any assumptions about the original ordering
of the items.

In this case you want to get a unique list of brokers based on their Id
values.  Here is a stylesheet that picks out your unique brokers - you can
modify it to produce the html that you want (I wrapped your example XML in a
"data" element"):

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

<xsl:key name='brokers' match='Broker'  use='Id'/>

<xsl:variable name='items'
 select='/data/Loan/BrokerSet/Broker[
    generate-id(Id)=generate-id(key("brokers",Id)[1]/Id)]'/>

<xsl:template match="/">
<results>
<xsl:for-each select='$items'><!--This is a unique list -->
 <item><xsl:value-of select='Id'/></item>
</xsl:for-each>
</results>
</xsl:template>
</xsl:stylesheet>

Cheers,

Tom P


 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.