Using XSL-FO and HTML? - xslt

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?

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.

XSL-FO is for PDF display only (this is not strictly true, but you can take it as a guideline). So HTML output and FO output are not related. From your XML source, you can use XSLT to generate XHTML or XSL-FO, but not both at the same time.
See for example DocBook. It comes with several XSLT stylesheets ready to use, one is for HTML output and one for PDF (via Apache Fop). If you are satisfied with the result could be a different question.

Related

Any Decent Open Source XSLT designers for XSL-FO output [ WYSIWYG style]

We are planning to render millions of pdf's using Apache FOP by using XSL-FO as input.
Is there a decent XSLT WYSIWYG designer that allows to easily design an XSLT that will transform the XML input data to the XSL-FO required for processing by FOP?
I see a lot of commercial ones - Ecrion , Antenna House.. Any open source ones?
The only somewhat decent editor that I have found is MiniScribus Scribe but I gut stuck with it at the point of wanting to put a horizontal line and the opened odt file lost its table format in Scribe... it says that it doesnt support yet headers/footers and table borders... not so decent.
There are some converters that could be of good use, like html 2 fo and odt to fo converters but the fo code generated by them returned a lot of exceptions from the Apache's FOP processor. The odt/html file with which I was testing had only a table, two horizontal lines and some unformatted text and only one page.
These tools, the convertors and the editor as well are now in beta phase so maybe there will a decent solution, so far I have not been able to find it.

XSL FO Repeat contents of split spanned cell

I am using apache FOP 0.95 (and docbook on top of it) and I would like to repeat the content of a table cell spanning multiple rows whenever a page break happens. At the moment the cell content is only displayed on the first page while an empty cell is displayed in all other pages.
I know this is part of the XSL FO 2.0 requirements, I believe not yet final.
I am a beginner with xsl transformations and I was wondering if there is a way to define a template to achieve this.
Thanks,
Pierpaolo
I am a beginner with xsl transformations and I was wondering if there is a way to define a template to achieve this.
The answer is almost certainly no. You are referring to a suggested new feature that might be included in a future XSL (XSL-FO) specification. Conformant XSL-FO processors will implement the feature if it is considered valuable enough.
XSLT and XSL-FO are related in the sense that the former is the most common way to generate the latter. But in general, you can't enhance the functionality of an XSL-FO processor by writing a clever XSLT stylesheet.

XSLT to convert an XML element containing RTF data to HTML?

OK, so here's the background:
We have a third-party piece of software that does a lot of complicated stuff to generate an XML file from a lot of tables based on a wide array of business rules. The software allows you to apply an XSL transformation by supplying an XSLT file as part of its workflow, before continuing on in the process, which is usually an upload to one or more servers, based on more business rules.
Here's the problem:
One of the elements (with more on the way) this application is processing contains RTF text, and needs to be converted into formatted HTML before being uploaded. There are no means of transforming the XML inside the application other than through an XSLT file, and once we output the file, we cannot resume the workflow. My original thought was, "Easy! someone must have written a few XSL transforms for converting RTF to formatted HTML!" Hours of searching later, I must conclude I either suck at searching or it's awfully obscure.
Disclaimers:
I know the software is pretty darned limited; I'm stuck with it.
I know there are a lot of third-party tools to do this; they are not available to me because I would need to run them externally.
I know that this is not a pretty or efficient thing to do with XSLT. Changing that is not an option for me at this point.
If I cannot find a means to do this through pure XSL transforms, I will need to output the files locally, run the extra process, and take the destination routing on through a custom process. I really don't want to do that.
Does anyone have access to an XSL transformation function/ scheme that will allow me to do this natively in the application? Perhaps a series of regular expressions I could use or something?
So it turns out that external scripts can be invoked from the XSLT. It seems I will be using another scripting language to get this to work. I'm a little bummed there was no other answer available.

Is there a free C++ xsl-fo to PDF engine?

Is there an xsl-fo to PDF engine written in C++ that can be used in QT?
The engines I have come across so far are in java.
You should use QXmlQuery: link
From qt docs:
Running an XSLT stylesheet is like running an XQuery, except that when you construct your QXmlQuery, you must pass QXmlQuery::XSLT20 to tell QXmlQuery to interpret whatever it gets from setQuery() as an XSLT stylesheet instead of as an XQuery. You must also set the input document by calling setFocus().
Code:
QXmlQuery query(QXmlQuery::XSLT20);
query.setFocus(QUrl("myInput.xml"));
query.setQuery(QUrl("myStylesheet.xsl"));
query.evaluateTo(out);
where "out" is pdf file. and xsl file define how to trasform your xml file to pdf.

what is the best way to write xslt -fo out of xsl+xml

i have complex xslt that formats xml to html
now i need to be able to create xsl fo out of it
what is the best way to do it ?
Here is some ineresting article for you
http://www-128.ibm.com/developerworks/library/x-xslfo2app/
Also you can try next library (I dont't remember, probably it can creat fo files from xslt+xml):
http://www.codeproject.com/KB/dotnet/nfop.aspx
I had a similar requirement, and I did some research, but didn't find a reliable XHTML to FO transformer. There may be one, but there comes a point in some web searches when you have to give up and roll your own.
Instead I took the XML to HTML transformer I had already written and changed it to output FO.
This is a much simpler proposition that a full blown XHTML to FO transformer.
Whilst your details will differ, most structures in HTML have analogues in FO, so you can normally decide what FO construct to use in replacing HTML in your transform fairly easily.
I did this incrementally. If you start with the transform producing the outline of an FO document, and most of your XML being ignored in the transform, you can then build up the output in a measured fashion.