Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

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
[498 byte] By [Bob Rouse] at [2007-11-9 15:27:08]
# 1 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">
<xsl:output 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.dev-archive.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
>
Russell Jones at 2007-11-11 23:29:56 >