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

XML Databinding

I know how to bind the XML data to a HTML table but how can I bind the data
into a dropdown list?
Jeremy
[117 byte] By [Jeremy] at [2007-11-9 15:27:49]
# 1 Re: XML Databinding
"Jeremy" <cchoo13@hotmail.com> wrote:
>
>I know how to bind the XML data to a HTML table but how can I bind the data
>into a dropdown list?
here an exaple

XMLFile1.xml
------------
<?xml version="1.0" encoding="utf-8" ?>
<?xml:stylesheet type="text/xsl" href="test.xsl"?>
<list>
<item>Item 1</item>
<item>Item 2</item>
<item>Item 3</item>
<item>Item 4</item>
</list>
-------------

test.xsl
-------------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<P><BUTTON ONCLICK="window.alert(document.body.innerHTML);">View HTML</BUTTON></P>

<select name="mylist">
<xsl:for-each select="/list/item">
<option>
<xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>

<xsl:value-of select="."/>
</option>
</xsl:for-each>
</select>
</xsl:template>
</xsl:stylesheet>
-------------
Altay Karaku at 2007-11-11 23:29:47 >
# 2 Re: XML Databinding
that's really helpful, but the problem is.. it is not a XSL, it is a ASP (assignment
requirement). So, is there another way of doing that?
Jeremy at 2007-11-11 23:30:47 >
# 3 Re: XML Databinding
"Jeremy" <cchoo13@hotmail.com> wrote:
>
>I know how to bind the XML data to a HTML table but how can I bind the data
>into a dropdown list?
>
>Jeremy
>
Jeremy this is a simple example of an xslt sheet that does that.
It builds both an un ordered list and a drop down box by creating the tags
with the xsl:element and xsl:attribute tags. I hope this helps you.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
<head><title>Flowers</title></head>
<body>
<h1>Flowers</h1>

<xsl:element name="ul">
<xsl:for-each select="//price">
<xsl:element name="li">
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:element>

<form>
<select>
<xsl:attribute name="name">common</xsl:attribute>
<xsl:for-each select="//flower">
<option>
<xsl:attribute name="value">
<xsl:value-of select="price"/>
</xsl:attribute>
<xsl:value-of select="name/common"/>
</option>
</xsl:for-each>

</select>
</form>

</body>
</html>

</xsl:template>

</xsl:stylesheet>
Clarence Royal at 2007-11-11 23:31:52 >
# 4 Re: XML Databinding
Jeremy,

I am not sure if you ever got an answer to your question, but I have been
battling this issue for the last 3 business days without any luck. I am
trying to fill a select drop down list with an attribute value from each
element in an xml object in ASP. If you ever get an answer to that let me
know. If I find it first I will email you.

Best wishes!

Scott

"Jeremy" <cchoo13@hotmail.com> wrote:
>
>that's really helpful, but the problem is.. it is not a XSL, it is a ASP
(assignment
>requirement). So, is there another way of doing that?
Scott at 2007-11-11 23:32:46 >
# 5 Re: XML Databinding
"Jeremy" <cchoo13@hotmail.com> wrote:
>
>I know how to bind the XML data to a HTML table but how can I bind the data
>into a dropdown list?
>
>Jeremy
>
The dataselect behavior from Microsoft is a dropdown list that can bind to
xml data islands.
Here's a link to download it.
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/behaviors/library/dataselect/default.asp
Bill Burchfield at 2007-11-11 23:33:50 >
# 6 Re: XML Databinding
I don't know if you ever found an answer, but I just ran across this online. Since I don't know anything about ASP, all I can do is pass this along to you hoping it will be useful. It seems to be exactly what you are looking for.

http://www.eggheadcafe.com/articles/20011128.asp
coveyte at 2007-11-11 23:34:54 >