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

Re: Writing a SELECT with each OPTION a unique value

Subject: Re: Writing a SELECT with each OPTION a unique value
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 11 Apr 2007 07:30:52 +0530
Re:  Writing a SELECT with each OPTION a unique value
On 4/11/07, Waters, Tyler S FOR:EX <Tyler.Waters@xxxxxxxxx> wrote:
<?xml version="1.0" encoding="ISO8859-1" ?>
<CATALOG>
       <CD>
               <TITLE>Empire Burlesque</TITLE>
               <ARTIST>Bob Dylan</ARTIST>
               <COUNTRY>USA</COUNTRY>
               <COMPANY>Columbia</COMPANY>
               <PRICE>10.90</PRICE>
               <YEAR>1985</YEAR>
       </CD>
       <CD>
               <TITLE>Hide your heart</TITLE>
               <ARTIST>Bonnie Tylor</ARTIST>
               <COUNTRY>UK</COUNTRY>
               <COMPANY>CBS Records</COMPANY>
               <PRICE>9.90</PRICE>
               <YEAR>1988</YEAR>
       </CD>
</CATALOG>
<xsl:key name="KEY_COUNTRY" match="CD" use="COUNTRY" />
 -- indexes all the items based on country

This is a XSLT 1.0 technique to get unique values (known as Muenchian method):


<xsl:for-each select="CATALOG/CD[generate-id() =
generate-id(key('KEY_COUNTRY', COUNTRY)[1])]">
 <xsl:value-of select="COUNTRY" /><br/>
</xsl:for-each>

With XSLT 2.0, you can use distinct-values function:

<xsl:for-each select="distinct-values(CATALOG/CD/COUNTRY)">
  <xsl:value-of select="." /><br/>
</xsl:for-each>

--
Regards,
Mukul Gandhi

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-2011 All Rights Reserved.