cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert, Kevin" <kjalb...@software.rockwell.com>
Subject RE: How to set tag attributes using appendChild
Date Tue, 13 Jun 2000 14:36:53 GMT
I haven't tested ... but I think you want to do something like this:

Element new_option = document.createElement("option"); // create the option 

new_option.setAttribute("value", "Banana");

new_option.appendChild(document.createTextNode("Banana")); // set the value 

Regards, Kevin Albert


-----Original Message-----
From: Chris Newland [mailto:cnewland@nortelnetworks.com]
Sent: Tuesday, June 13, 2000 7:54 AM
To: Cocoon User Mailing List (E-mail)
Subject: 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. 
------------------------------------------------------------ 


Mime
View raw message