| Author |
Dynamic XML to HTML
|
Finn MacCool
Greenhorn
Joined: May 23, 2006
Posts: 9
|
|
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?
|
 |
Dave Lenton
Ranch Hand
Joined: Jan 20, 2005
Posts: 1241
|
|
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: XML: XSL: 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
|
 |
Finn MacCool
Greenhorn
Joined: May 23, 2006
Posts: 9
|
|
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. XML XSLT
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
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.
|
 |
Finn MacCool
Greenhorn
Joined: May 23, 2006
Posts: 9
|
|
|
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?
|
 |
Dave Lenton
Ranch Hand
Joined: Jan 20, 2005
Posts: 1241
|
|
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: Also, check out this site, it has loads of solutions to tricky XSL problems: http://www.dpawson.co.uk/xsl/sect2/sect21.html [ June 14, 2006: Message edited by: Dave Lenton ]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
To output XHTML instead of XML?as a child of your xsl:stylesheet element. (Arrgh! I thought they set the XML forum up to automatically disable smilies. Edited.) [ June 14, 2006: Message edited by: Paul Clapham ]
|
 |
Finn MacCool
Greenhorn
Joined: May 23, 2006
Posts: 9
|
|
|
Thanks guys, you've both been a great help! Cheers.
|
 |
 |
|
|
subject: Dynamic XML to HTML
|
|
|