I use this HTML to convert it to pdf, and this must have "well formated" tags :-(
(for example on img-tags: it must have end tags..)
If you use whatever library/framework/utility-software which advertises that it can convert html to pdf, it better delivers without complaining the output not a bit.
[1] Now, if it won't deliver their promise, you can still at the xslt-output end of the chain of processes insert a step using with some api/utility usually called "html repair" or "beautifier" before passing to the broken html-pdf converter.
[2] You can do better by doing the necessary at the earlier stage of the chain of processes that I have already answered, namely. I quote myself, If you want a well-formed output (html) you put the method="xml", unquote. If you do not catch the gist of it, you do the following in the xslt.
I think this is the most readily understandable step you can take to end up with a conversion to pdf.
[3] Better still, you can do the following chain of processes, using xsl-fo (format-object) and use say Apache's fop to convert to pdf. Just to mention in passing, as I don't see you are ready for it yet.
[3.1] You can also not using Apache fop or some commercial equivalence, but instead use some other dedicated framework/library such as iText or something else to spare you from producing some useless intermediate objects such as html and directly convert the xml source to pdf adding the image on the way of doing it.