4

I have an HTML form on which I have no control, and I would like to display the contents (labels AND input text/choices) to the client with another layout on the page (actually, to do a "review your answers" page).

So I pretty much need to transform a complex HTML form into another HTML doc (or DOM node tree).

It seems to me very close to the usual use case for XSL transformations, except that the input is not XML.

I just wonder if XLST is the de-facto way to go to do that, or if I could use another technique (maybe better suited for non-XML input)?

lajarre
  • 4,910
  • 6
  • 42
  • 69
  • You might like to look at a previous post: http://stackoverflow.com/questions/138555/how-to-convert-html-to-xhtml – resigned Oct 29 '13 at 22:06

1 Answers1

3

No, you can't do this, because HTML is no XML (unless it is of doctype xhtml).

Let me explain with a simple example:

<html>
    <body>
        <p>Para1
        <br>
        <p>Para2</p>
    </body>
</html>

This is a valid HTML-fragment, but not a wellformed XML. And you cannot transform invalid XML with XSL.

If you can manage to transform the (invallid) HTML tp valid xhtm, before you transform it via XSLT, it may work. You can try this by using jtidy, but I have no experience with jtidy,

Christian Kuetbach
  • 15,850
  • 5
  • 43
  • 79