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
329 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 62

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

789 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