You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Chris Newland <cn...@nortelnetworks.com> on 2000/06/13 14:53:41 UTC
How to set tag attributes using appendChild
Hi All,
I'm trying to generate XML dynamically using the DOM interface but I'm
having trouble creating attributes and attaching them to the tags I'm
creating.
I'm trying to make a dynamic form 'select' structure but I can't seem to
attach a 'value' attribute to each option I create.
This is not a problem for HTML (IE5) since it takes the name as the value if
no value is specified:
<select name="fruit">
<option>Banana</option>
<option>Apple</option>
</select>
The problem I'm having is when trying to apply a WML stylesheet since my WAP
device (the Nokia simulator) expects
<select name="fruit">
<option value="Banana">Banana</option>
<option value="Apple">Apple</option>
</select>
I'm trying to attach the attribute 'value' to the 'option' tag like this:
Element new_option = document.createElement("option"); // create the option
new_option.appendChild(document.createTextNode("Banana")); // set the value
Element new_value = document.createElement("value"); // create the value
new_value.appendChild(document.createTextNode("Banana")); // set the value
new_option.appendChild(new_value); // append the value to the option
// finally append the option to the select
my WML XSL code looks like this:
<select name="fruit">
<xsl:for-each select="option">
<option><xsl:apply-templates/></option>
</xsl:for-each>
</select>
but the generated WML comes out as:
<select name="fruit">
<option>BananaBanana</option>
<option>AppleApple</option>
</select>
I've played around with this for ages now but I can't work out what I'm
doing wrong.
Any help would be greatly appreciated.
Thanks
Chris
--
Chris Newland
Software Research Engineer
Advanced IP Services and Management
Nortel Networks, London Road, Harlow, Essex, CM17 9NA.
Tel: +44(0)1279 405165
Fax: +44(0)1279 402047
Email: cnewland@nortelnetworks.com
"This message may contain information proprietary to Nortel Networks
so any unauthorised disclosure, copying or distribution of its
contents is strictly prohibited."
------------------------------------------------------------
Company name: Nortel Networks plc
Company number: 2515751
Company's registered office address: Maidenhead Office Park,
Westacott Way, Maidenhead, Berkshire SL6 3QH.
------------------------------------------------------------