Search code examples
xmlxsltapache-fop

Apache FOP and normal XSL stylesheet


I've an xml returned from a web service. This xml is a label used by a courier. The API specifies also the XSLT stylesheet. I had success to produce an HTML page using XML+XSLT (i'm using Java).

I need to produce a PDF label because it must be sent to the final user.

Does exists a way to use standard XSL stylesheet instead of XSL-FO?

Does exists another solution?


Solution

  • You are confusing things. XSL-FO is a Markup-Language (of XML format):

    XSL-FO (XSL Formatting Objects) is a markup language for XML document formatting that is most often used to generate PDF files. XSL-FO is part of XSL (Extensible Stylesheet Language), a set of W3C technologies designed for the transformation and formatting of XML data. The other parts of XSL are XSLT and XPath. Version 1.1 of XSL-FO was published in 2006.

    XSLT on the other hand is [a possibly] Turing-complete [language], making it theoretically capable of arbitrary computations [...]:

    XSLT is [...] a language for transforming XML documents into other XML documents,[1] or other formats such as HTML for web pages, plain text or XSL-FO[...]

    Your question

    Does exists another solution?

    can be answered with: You are using the probably best way to handle things.

    Of course there do exist other ways to transform XML files to PDFs, but as you described your workflow, this is probably a very good approach at handling things.

    If you'd like to optimize it, I would suggest to go fully XSLT (version 3.0) and reduce the Java part as much as possible.

    I need to produce a PDF label because it must be sent to the final user.

    XSLT can transform your input XML to HTML and XSL-FO - and Apache FOP can output to PDF. So you are able to satisfy all of your needs with probably one XSLT file - standard conform and configurable.

    So your workflow could be:

    XML by Courier   ->    XSLT----(1)-->   HTML
                            |
                            -------(2)-->   XSL-FO  ---(FOP)--->  PDF