• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic XML to HTML

 
Finn MacCool
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Finn MacCool
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, you've both been a great help! Cheers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic