[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: best way to generate form from xml+schema?

Subject: RE: best way to generate form from xml+schema?
From: "Chris Bayes" <chris@xxxxxxxxxxx>
Date: Tue, 16 Oct 2001 14:22:12 +0100
generate form from xml
>At the moment, the only idea I have for that is 
> to give the cgi parameters names which reflect the xml 
> structure (eg not 'email', but 
> 'programItem:submitter:email'). Write the parameters to a 
> temporary file. Then use a stylesheet heavily dependent on 
> 'substring-after' functions to generate an xml file with 
> expanded versions of the parameters (eg <programItem>
> 	<submitter>
> 		<email>a@xxx</email>
> 	</submitter>
> </programItem> 
> Then read this into a second stylesheet which also reads in 
> the schema to generate the full xml file. 

Wow! I would suggest a liberal use of <div elements in your form that
reflect your xml. Then instead of submitting the form as is you have an
onsubmit function that wanders over your form constructing an xml string
which you then post back to the server. Something like.
<form name="x" onsubmit="post(this)">
	<div name="xml_element_name">
		<input type="text" name="xml_element_name"
cjb:type="attribute" />
		<input type="text" name="xml_element_name"
cjb:type="text" />
		<div name="xml_element_name">
			<input type="text" name="xml_element_name"
cjb:type="attribute" />
			<input type="text" name="xml_element_name"
cjb:type="text" />
		</div>
	</div>
</form>
function post(obj){
	var postString = wander(obj);
	var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	xmlhttp.Open("POST", "http://someplace", false);
    	xmlhttp.Send(postString);
}
function wander(obj){
	var retStr = "";
	if (obj.tagName == "DIV"){
		retStr += "<" + obj.name + " ";
		for (var i=0; i<obj.childNodes.length; i++){
			if (obj.childNodes[i].tagName == "INPUT"){
				if
(obj.childNodes[i].getAttribute("cjb:type") == "attribute"){
					retStr += obj.childNodes[i].name
+ "=" + obj.childNodes[i].value;
				}else{
					retStr += ">" +
obj.childNodes[i].value;
				}
			}else{
				retStr += wander(obj.childNodes[i]);
			}
		}
		retStr += "</" + obj.name + ">";
	}
	return retStr;
}
It would be a lot easier to use xslt and use the form.innerHTML as the
input to the transform but the problem is that the innerHTML is nowhere
near valid xml.

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.