Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 20th, 2007, 06:57 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default distinct data from XML using XSL

Hi
I have an XML file which I am trying to view in a drop down list, basically I want the drop down list on an ASP.net page to select only distinct values from an element, example:
<BANKS>
<Bank>
    <bank>BANK1</bank>
    <branch>city1 </branch>
    <address1> </address1>
  </Bank>
  <Bank>
    <bank> BANK1</bank>
    <branch>city </branch>
    <address1>home </address1>
  </Bank>
  <Bank>
    <bank> BANK2</bank>
    <branch>city </branch>
    <address1>home </address1>
  </Bank>
</BANKS>

So basically I want my drop down list to provide me with the following options:
BANK1
BANK2


I have the following in an XSL file, but it’s still not working:
     <xsl:for-each select="/Banks/Bank[not(bank = preceding-sibling::Bank/bank)]">
         <xsl:sort select="bank" data-type="text" order="ascending"/>
          <xsl:value-of select="bank"/>

      </xsl:for-each>

Aspx:
<asp:DropDownList ID="ddl_Banks" runat="server" DataSourceID="XmlDataSource1"
    DataTextField="bank" DataValueField="nsc" Width="184px" ></asp:DropDownList>


        <asp:XmlDataSource ID="XmlDataSource1" runat="server"
         DataFile="~/Banks.xml" TransformFile="~/Banks.xsl"></asp:XmlDataSource>


Any ideas?
__________________
Thank You
 
Old November 20th, 2007, 07:20 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Removing duplicates is a task that generally goes under the name "grouping". In XSLT 2.0 there is an <xsl:for-each-group> instruction that makes this easy. In 1.0 it's quite tricky but there is lots of advice available. Look up "grouping" in your favourite XSLT textbook, or go to http://www.jenitennison.com/xslt/grouping.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 20th, 2007, 09:40 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

would you have an example, im very new to XSL.
 
Old November 20th, 2007, 09:54 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Michael posted a link that has three grouping examples, what more do you want?

--

Joe (Microsoft MVP - XML)
 
Old November 20th, 2007, 10:06 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

If you're going to tackle grouping problems using XSLT then I would recommend getting yourself a book on the language and spending a few days studying it. Best choice depends on your programming experience and preferences - mine is a very comprehensive reference, Jeni Tennison's "Beginning XSLT 2.0" is a gentler introduction for beginners.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 20th, 2007, 10:25 AM
Authorized User
 
Join Date: Nov 2007
Posts: 67
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Hughesie78
Default

thanks a million





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL file can't find elements in XML data? Mateo1041 XSLT 2 September 18th, 2008 09:37 AM
XSL: Display distinct values elayaraja.s XSLT 1 July 17th, 2008 07:00 AM
Getting data from xml and xsl files combined hema_latha7 General .NET 0 May 19th, 2006 08:27 AM
getting data from XML rendering with XSL louismanukonda XSLT 1 January 4th, 2006 10:37 AM
XML to HTML Table with Sorting and Distinct VictorMk XSLT 4 April 23rd, 2004 06:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.