-
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
-
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 utput 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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks