|
[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
[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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








