Solved

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
7
299 Views
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.
0
Comment
Question by:nlpalmquist
  • 3
  • 3
7 Comments
 
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
0
 
LVL 61

Expert Comment

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

Author Comment

by:nlpalmquist
ID: 40232084
Geert,

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.
Mvehicleprt-pdf.xsl
car2.xml
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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
0
 

Author Comment

by:nlpalmquist
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,
so
<td>Something<td>

would change to
  <fo:table-cell border="solid 1px black">
            <fo:block font-weight="bold">Something</fo:block>
     </fo:table-cell>
    <fo:table-cell>
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.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 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
0
 

Author Closing Comment

by:nlpalmquist
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.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now