This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Is there a way to dynamically create a HTML page with labels/input fields from an XML document?
XSLT requires that you know the name of the fields and I understand is only useful if you want to display the XML as a 'fancy' webpage, but can you use it to create a page that can be filled out and submitted?
Originally posted by Finn MacCool: XSLT requires that you know the name of the fields and I understand is only useful if you want to display the XML as a 'fancy' webpage, but can you use it to create a page that can be filled out and submitted?
I'm not really sure what you mean here, but XSLT is able to produce forms with names and types based upon values in XML. For example you could have something like:
Basically you can make a template for each type of form item you wish to create, and then use them to create a HTML form dynamically based upon some input XML. [ June 09, 2006: Message edited by: Dave Lenton ]
There will be glitches in my transition from being a saloon bar sage to a world statesman. - Tony Banks
Joined: May 23, 2006
Hi Dave, I already tried something similar, but it wasn't working properly (the resulting HTML wouldn't close the input tag properly). Here's a copy of the XML and XSLT I was trying as an example, if you can see anything wrong with it please let me know.
I see your <input> element, but in my view the problem with it is that it isn't inside a <form> element.
As for "not closing the input tag", you're outputting HTML 4.0. Unlike XHTML, it doesn't require input tags to be closed.
Joined: May 23, 2006
Thanks Paul, I've chucked in the form tags now. About the output being HTML 4.0 - is there a way to make it output in XHTML? Also, in my example above the name of the input text field will always be the same for every instance it iterates, is there a way to specify this as a "variable" and add +1 to the name for each iteration or something similar?
Joined: Jan 20, 2005
You could use the functions position() or generate-id() to generate a different number for each input field. As you will probably want to know the name of each input field in order to get the values back out again (without having to know the order, in case you want to change it), a better option would be to add an id element to each cd element, and then do this: