I still have about 7 chapters to go to get a better understanding of XSLT, but I've done basic XML->HTML transformations already. I have a nice HTML/CSS template that I'd like to use for my project, but since an XSL file is XML, then the parser will be picky - and rightly so. HTML has its quirks (ok, a lot of them), and since it does, how can I make sure the parser actually parses everything while ignoring all the HTML in a file?
Having something like this works great:
But what if it's just a normal file with attributes and CSS, tags which are not closed, etc? Surely there must be a way and this is where I'm stuck with my project.
Oh, by the way - I'm using Saxon Home Edition for XSLT. Unfortunately it's version 6.5.5 as I just downloaded the Ubuntu package, but will probably upgrade it tomorrow to 9.3.
If I remember right, the correct approach is to make sure tags are closed. Imagine you're writing XHTML - make sure everything is well formed (CSS isn't a problem - it's in a <style> tag and should be plain text other than that). Then, the important part is the <xsl:output method="html"/> line. That tells the transformer to output HTML. So you put in a <br/> and it will output <br>, for instance.
I'm not sure I understand what you mean by "the HTML file" now. Do you have an HTML file which is going to be transformed by that XSLT? If so, yes, it has to be well-formed XML, but that isn't the usual process. Usually people just start with XML which doesn't have to be HTML in any way, and transform that into HTML.
Or if you're producing an HTML file from that XSLT, as your example shows, then what Matthew said is correct. Generate output with matching open and close tags and so on, and it's the transformer's job to produce real HTML. You don't have to post-process it.
Paul Clapham wrote:Do you have an HTML file which is going to be transformed by that XSLT? If so, yes, it has to be well-formed XML, but that isn't the usual process. Usually people just start with XML which doesn't have to be HTML in any way, and transform that into HTML.
Yes, exactly. I have a nice HTML/CSS template and I need XSLT to insert some text from an XML file into it. I did the following to remedy the problem: