Adding FO  to an existing XSL that was used to convert XML to HTML.  I need to generate a PDF version of the output

Posted on 2014-07-30
Medium Priority
Last Modified: 2014-08-06
I have a number of successful XML/XSL transformation that generate complex HTML pages.  I need to make instead a PDF that can be embedded in an XML file instead of an HTML that is displayed in response.  I have started with my simplest XML/XSL to figure out how to make this work.

I see in docs that this is a two step process but I am not sure how I need to accomplish this solution.

I find tutorials on XSL with fo, but do I use my current transformation and output XML, then run that through another XSL with the FO commands to apply formatting to tables and such.  Or is this stuff I need to add to my current XSL sheet by inserting FO entries throughout my format?

The biggest part of the output is various tables, so it would be nice to be able to adjust the "class" attributes I use to format into ones that pick up formatting from the fo templates and attributes.

But I am not clear on the overall approach.  Once I get that ahh-haa moment when I can see to full picture I can start hitting the detail of what is needed.

BTW - I use <oXygen/> XML Editor to test my setups before I deploy them to the Linux Web Server with Apache FOP.  I did get a simple setup I found in Experts to work, but I can not seem to build that forward to function with my XSL.

I would be glad to provide samples if this is too vague.
Question by:nlpalmquist
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 60

Expert Comment

by:Geert Bormans
ID: 40230505
Since I have no clue about the complexity of the transforms, I give you some generic hints of what you can do (and what I have done before so I know it makes sense)

I usually take the other way round. If I need both XSL-FO and HTML, I tend to develop teh XSL-FO first and derive the HTML from there (using an XSLT that does XSL-FO into HTML (there is a good example on the RENDER-X website you can use as a basis to that

Your situation is different since you already have the XSLT for HTML.
If at all possible, try to start from the existing XHTML
If you need to use th eHTML as a starting point for the next XSLT you will need to change the output method
in the existing XSLT to have a wellformed XML as HTML (xsl:output method="xml")
I would consider that my first option, develop an XSLT that transforms an HTML into XSL-FO

second viable option means interfering the existing XSLT and overload templates, that is somewhat more advanced and we will discuss that if the first option does not work for you

If you are not bound to FOP but could eg. use ANtenna House Formatter instead... just add a different media type to your CSS and let Antenna House format the HTML + CSS into PDF. I did pretty fancy books using that technique

Using Oxygen transform scenarios you can set up pipelines by checking all transforms at once in the scenario, but I assume you knew that

good luck
LVL 62

Expert Comment

ID: 40231001
Nobody did it before,.. In 20 years of XSL and PDF...

Author Comment

ID: 40232084

I am stuck with Apache FOP.  Could you look at the xsl and rough in how I could add FO?  I have tried to follow tutorials and samples and I am missing something.

I have attached my last files.  Sample XML and my current version for XSL-FO.  Maybe I need to remove some of the HTML tags that make no sense like HEAD and BODY.

I have broken down my output to Headings, Body, and Footer.  Which I hope will generate a header on each page, the body that might run from page to page like a normal book by filling a page and then starting a new page, and a footer on each page.

It seems to generate what looks to me like a valid FO file.

I am not worried about the stylesheets, I figure I have to replace that by inserting some kind of FO:BLOCK and FO:INLINE but want to get a basic translation to work before I attempt that step.
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

LVL 60

Expert Comment

by:Geert Bormans
ID: 40232340
@gheist, I really don't know how to make sense of your comment

I have been creating PDF from XML, HTML and SGML for about 25 years now, using DSSSL, XSL-FO, OmniMark, XSLT, CSS, FrameMaker, InDesign,  and a whole bunch of high end publishing tools for really tricky books and demanding publishers... you might be surprised what can be done
Creating the PDF is the hard part, embedding it in XML is but a matter of referencing it (if a reference is acceptable) or encoding it using Base64 and stuffing that in as string text
SO I don't know what your problem is

@nlpalmquist, I will look into your xsl later this evening or tomorrow, will return from holidays two days from now, so can't rush it

Author Comment

ID: 40232708
I've been messing with this all day and the basic theory I have found is that I need to look at my HTML output document from my normal XML/XSL transformation like it is just another XML input document.  Maybe it needs a bit of tweaking for paging purposes at that first level.

If I do that I can look for HTML tags like <td></td> and and insert the FO commands into the document instead,

would change to
  <fo:table-cell border="solid 1px black">
            <fo:block font-weight="bold">Something</fo:block>
I figure I can apply templates to make this happen but I can only get a sample from one of the tutorials to work when it is just straight FO to start with.  

I don't see how to do that except to run my command line to make the HTML and then pick up the HTML document as the input XML and apply the FO stylesheet to make the PDF.

I have been trying to do both formats at the same time and maybe that is my problem.

I really appreciate any direction you can give me.  I can certainly build the details once I can get a small solution working.
LVL 60

Accepted Solution

Geert Bormans earned 2000 total points
ID: 40232966
basic theory I have found is that I need to look at my HTML output document from my normal XML/XSL transformation like it is just another XML input document.

Yes, that is exactly what I meant with my first option.
You might need to change the serialisation settings so that the input of the next transform is really XML (XHTML) and not HTML. Or don't serialise at all in between steps

The HTML table model does not match the FO table model 100%, so there is some tweaking to do other than just making each td into a fo:table-cell

Author Closing Comment

ID: 40244592
Thank you for confirming my assumptions.  I always find docs written by programmers to assume many things that should be stated more exactly.

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question