Building options list from XML


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Building options list from XML

  1. #1
    Bob Rouse Guest

    Building options list from XML


    I am trying to get an ASP page to dynamically populate an Options list for
    a "combo box" (drop down) Select control, based on XML retrieved from another
    ASP page (I can build the ASP internally, if necessary).

    I know how to process XML using DOM in VBScript, and I know how to add and
    delete entries from the options list using javascript, but I don't know how
    to do both in one language.

    Any advice would be appreciated...

    Thanks,

    Bob Rouse


  2. #2
    Russell Jones Guest

    Re: Building options list from XML

    You might find it easier to create the select list in one fell swoop using
    XSLT. For example, suppose you had this XML:
    <?xml version="1.0" encoding="UTF-8"?>
    <people>
    <person id="1">
    <lastname>Jones</lastname>
    <firstname>Bob</firstname>
    </person>
    <person id="2">
    <lastname>Templeton</lastname>
    <firstname>Franklin</firstname>
    </person>
    <person id="3">
    <lastname>Oppenheimer</lastname>
    <firstname>Marcie</firstname>
    </person>
    <person id="4">
    <lastname>Catterall</lastname>
    <firstname>Diane</firstname>
    </person>
    </people>

    And you want to create this select list:
    <select id="selPeople">
    <option id="4">Diane Catterall</option>
    <option id="1">Bob Jones</option>
    <option id="3">Marcie Oppenheimer</option>
    <option id="2">Franklin Templeton</option>
    </select>

    Then you could use an XSLT stylesheet such as this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xslutput method="html" encoding="UTF-8"/>
    <xsl:template match="/">
    <xsl:apply-templates select="people" />
    </xsl:template>

    <xsl:template match="people">
    <select id="selPeople">
    <xsl:apply-templates select="person">
    <xsl:sort select="lastname" data-type="text" order="ascending"/>
    </xsl:apply-templates>
    </select>
    </xsl:template>

    <xsl:template match="person">
    <option><xsl:attribute name="value"><xsl:value-of
    select="@id"/></xsl:attribute><xsl:value-of select="concat(firstname,'
    ',lastname)"/></option>
    </xsl:template>

    </xsl:stylesheet>

    Finally, you can use xsl parameters to make much more generic stylesheets
    than shown in this example.


    "Bob Rouse" <brouse@netuitive.com> wrote in message
    news:3dbea504$1@tnews.web.devx.com...
    >
    > I am trying to get an ASP page to dynamically populate an Options list for
    > a "combo box" (drop down) Select control, based on XML retrieved from

    another
    > ASP page (I can build the ASP internally, if necessary).
    >
    > I know how to process XML using DOM in VBScript, and I know how to add and
    > delete entries from the options list using javascript, but I don't know

    how
    > to do both in one language.
    >
    > Any advice would be appreciated...
    >
    > Thanks,
    >
    > Bob Rouse
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center