Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Binding XML 2

Status
Not open for further replies.

caf

Programmer
Joined
Sep 19, 2000
Messages
124
Location
ZA
Hi all
If anyone can help me I'd be forever grateful
Let me first explain my situation
[ul][li]I have an XML document (default.xml) that's generated server side[/li]
[li]I have an HTML document (default.html) that's linked to that XML document via id="dsoSomeXML" src="default.xml"[/li]
[li]I have a combo box (or select as it's known by some)
that needs to bound to that XML data source[/li]
[/ul]So, let's say my data source consists of a Unique Field & a Description Field for arguments sake....
Code:
<members><data>
<id>1</id>
<description>SGML</description>
</data><data>
<id>2</id>
<description>HTML</description>
</data><data>
<id>3</id>
<description>VRML</description>
</data></members>
I need to fill the combo box up with the Text (in this case HTML SGML & VRML) and assign the unique key the value of the option i.e
Code:
<select datasrc = &quot;#dsoSomeXML&quot; datafld = &quot;members&quot;>
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
</select>
Okay, I can achieve the above but it's going to mean mixing code with presentation (I'm using Webclasses & I don't want to embed HTML in my business layer because if I need to make changes I'd have to recompile.
If you're familiar with Webclasses I'll explain
Here's a fragment of my HTML
Code:
.......
<select><WC@options></WC@options></select>
.......
I then generate the <option> tags in my dll
I'm mixing tiers and going against the concepts of n-tier development.

I can fill my select box using XSL which means keeping Presentation from content but I cannot assign the unique key

Here's a fragment of my XSL
Code:
.............
<select id=&quot;cboOptions&quot;>
<xsl:for-each select=&quot;members/data&quot;>
<option><xsl:value-of select=&quot;description&quot;></xsl:value-of>
</option></xsl:for-each>
</select>
.............
As you can see I use the XSL loop to fill my select box
The question I'm asking is....(sorry I've not been clear)

How can I assign <xsl:value-of select=&quot;id&quot;> to <option value = id goes here>???

Please help

thanx
Craig
 
Please ignore the tgml embedded in the examples
I just saw my post did not process the tgml when inside code tags
so
Code:
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
<option value = [COLOR=red]Unique key goes here[/color][b]>Description Goes Here[/b]
</select>

thanx
caf

should read.....

<option value = Unique key goes here>Description Goes Here
<option value = Unique key goes here>Description Goes Here
<option value = Unique key goes here>Description Goes Here
</select>
 
hello, caf

What kind of XSL processor do you use?
Did you tried to type XSL fragments like this:

<select id=&quot;cboOptions&quot;>
<xsl:for-each select=&quot;members/data&quot;>
<option value=&quot;{id}&quot;><xsl:value-of select=&quot;description&quot;/></option></xsl:for-each>
</select>

or like this:

<select id=&quot;cboOptions&quot;>
<xsl:for-each select=&quot;members/data&quot;>
<option>
<xsl:attribute name=&quot;value&quot;><xsl:value-of select=&quot;id&quot;/></xsl:attribute>
<xsl:value-of select=&quot;description&quot;></xsl:value-of>
</option></xsl:for-each>
</select>

?
 
Brilliant!

Thanx Avator

I've been battling with this some time. Serves me right for taking XSL lightly.
You get a purple star for your troubles
Here's my working code

<xsl:template match=&quot;/&quot;>
<html>
<head>
<script language=&quot;JavaScript&quot;>
function showValue() {.......}
</script>
</head>
<body>
<select id =&quot;combo1&quot; onchange=&quot;showValue();&quot;>
<xsl:for-each select=&quot;recordset&quot;>
<xsl:apply-templates select=&quot;row&quot;/>
</xsl:for-each>
</select>
</body>
</html>
</xsl:template>

<xsl:template match=&quot;row&quot;>
<option>
<xsl:attribute name=&quot;value&quot;><xsl:value-of select = &quot;@id&quot; /></xsl:attribute>
<xsl:eval>FormatEmpID()</xsl:eval>
</option>
</xsl:template>

<xsl:script language=&quot;JScript&quot;>
<![CDATA[

LASTNAME = 1
FIRSTNAME = 2

function FormatEmpID() {
list = this.selectNodes(&quot;field&quot;);

if(list.length > 0) {
str = &quot;&quot;;
str = list.item(FIRSTNAME).text + &quot; &quot; +
list.item(LASTNAME).text;

return str;
}
}

]]>
</xsl:script>
</xsl:stylesheet>

It works perfectly.

Have fun
caf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top