Using XSL-FO and HTML?

buggy1985 picture buggy1985 · Apr 30, 2010 · Viewed 8.8k times · Source

I'm trying to transform some XML-data to HTML with XSLT for my bachelor thesis.

My professor wants me to consider XSL-FO too, or at least to write some word about it. But I'm very noob to this.

So my questions are:

Can I combine FO with HTML? Can I use FO istead of HTML and CSS? If yes, how will my browser render this? Are there any examples/tutorials on how to transform xml into web pages with FO?

Answer

Mads Hansen picture Mads Hansen · May 1, 2010

Generating XSL-FO and XHTML from XSLT is not necessarily an either-or choice.

XSL-FO is generally used to generate PDF. For that you will need an XSL-FO engine, such as FOP, RenderX, Antenna House, IBex, etc. However, you can convert XSL-FO into XHTML and then render in the browser.

Generally, it wouldn't be worth the hassle to have your XSLT create XSL-FO and then convert into XHTML (just generate XHTML directly), unless you want to create both output formats (PDF and XHTML) with reduced effort.

It is possible to create both **XSL-FO and XHTML at the same time without maintaining two complete sets of stylesheets to create similar output in different vocabularies**.

Rather than choosing between one format or the other, or having to maintain two distinctly diffirent(but similar) stylesheet libraries, you can create your main stylesheet library to generate either XSL-FO or XHTML and then use a second transform to convert from XSL-FO to XHTML and vice-versa. There are existing XSLT stylesheets that you can leverage to do this.

In the past I have developed XSL-FO stylesheets and then used the Render-X FO2HTML stylesheet to convert the XSL-FO to XHTML output. It converts <block> elements into <div>, <inline> into <span>, etc.

I haven't used them before, but you could also try using HTML2FO stylesheets to convert XHTML outut into XSL-FO.

Out of the box, you can get amazingly similar output in both formats while maintaining one XSLT library dedicated to one particular output format.

If you happen to need to customize the output slightly (e.g. different header content for XHTML) then you just need to import/extend the conversion stylesheets and override the appropriate template(s) for the divergent content. This makes maintenance much easier, so you don't have to worry about updating multiple sets of stylesheets with essentially the same information.