How to generate a xslt file from xml - java

I'm beginner with xml and xsl. I'm looking for the way to generate or understanding how is the using of xsl stylesheet. In my particular case, I'm using a html file which it converts to xhtml. The next step I want to convert is the file generated to xsl-fo but I've seen I have to use a xslt stylesheet to do that. My question is about this file. How is it generate this xsl file? Is generated from the xhtml file?
Thanks!

Antenna House provides a sample XHTML to XSL-FO stylesheet under the 'XHTML to XSL-FO' tab at http://www.antennahouse.com/antenna1/xml-to-xsl-fo-stylesheets/. There's also an XSL-FO tutorial available under the 'XML to XSL-FO' tab.

Generally, the XSL file for an XSL-FO conversion is not generated. You'll have to create this file yourself. It contains a lot of information not present in the XHTML, for example page layouts.
XSL-FO is a bit like CSS, yes. The difference is that XSL-FO has lots more options, so an XSL-FO file is 100 times longer than a CSS file.
Here's an introduction to XSL-FO.
And another tutorial.

Okay this site can give you some helps to generate xslfo site.
Abd if you wont the contrary this site is fine
XSL FO to HTML Converter

Related

Having Freemarker-like templates for PDF generation (with itext)

In Java Project, i would like to use a Freemarker or something similar to it
(Quick start guide), but to generate a PDF file (textual), with IText for example.
Of cource, the workflow could be like that:
Template (Freemarker) -> Text (IText) -> PDF
...but I feel it is kind of a naive approach. I want to have in the PDF some formattings, tables, etc.
Anyone knows how to design it properly?
As PDF is a binary format, the best seems to generate some standard text format for which there exists a PDF conversion.
Texts --[FreeMarker]--> HTML or --[HTML-to-iText]--> PDF
DocBook XML
This also allows validation of the FreeMarker templates.

Support for external CSS file from Apache FOP PDF Generation

Does the apache FOP supports external CSS file for generating PDF from html document? I am specifying the css file path html file but styles are not applied on pdf report generated. Also I tried copy pasting the entire style content inside tag in html document. Still generated report does not the style applied. Since I am the beginner for FOP, I would be really great if someone tells me What am I missing here?
Another fundamental question would be.. does the Apache FOP supports external css file?
To use CSS with XSL FO you would need something that processes CSS into XSL FO. You can look at the link below which is not Apache FOP but uses RenderX XEP behind the scenes. It allows for XML and/or HTML with CSS internal and external, leveraging XSL FO technology to format content.
http://www.cloudformatter.com/CSS2Pdf

xsl stylesheet for generating word documents from Java

I was wondering if there is any Java API which allows to generate Word document similarly Apache FOP does.
With FOP, it is possible to specify a style sheet which defines the layout of the page in which the data (stored in an xml file) are printed.
The Transformer object within FOP library is in charge of that.
Is there any equivalent API for word document?
With FOP, you can try XML to RTF, which Word accepts.
From their webpage, XMLmind XSL-FO Converter apparently generates:
RTF (can be opened in Word 2000+),
WordprocessingML (can be opened inWord 2003+),
Office Open XML (.docx, can be opened in Word 2007+),
Putting FO to one side, here are 2 different approaches:
The first would be to write an XSLT to convert your XML to Flat OPC XML. Most parts in the Flat OPC XML would simply be copied there by your XSLT. (Generate that template content in Word, using "save as XML"). You'll be focusing mainly on populating the document.xml part. Word can open a Flat OPC XML file, or you can use docx4j (a project I work on) to convert Flat OPC XML to docx.
The second would be to use the docx4j Flying Saucer fork to convert your XML + CSS to docx content. See the code samples. You may need to customise it a bit; one way of feeding it CSS is this file. This actually ought to work pretty well; there is stuff there for mapping class attributes to Word styles, so if you could adorn your XML with class attributes, you could get even better results.
I will assume that your input is an XML document, or at least a CSV file.
1) Create an XSLT stylesheet to transform your input into the Word document format. The result will be a file we will call content.xml. You can apply the stylesheet to the input from Java.
2) Create a MS Word shell and put the content.xml into the shell. There are tools within Apache POI to do this.
I may have taken your question too literally. You might also be able to generate the document using Apache POI API. Also, if your MS Word document doesn't have tables, you can use Apache FOP to generate an RTF document, which can then be easily translated to a .docx file.
Apache POI provides Java APIs for reading and writing Microsoft Excel, Word, and PowerPoint files.
You can checkout POI's Javadocs here.

Converting XML to PDF, using styles from XSL

I have following problem: I have a XML file with XSL stylesheet, that is rendering this XML file as neat table in HTML when I load it in web browser. Now I need to make a PDF that is looking EXACTLY like that XSL-styled XML in web browser, without need for making custom FO's for every file. Everything must be done in Java.
I need to make a PDF that is looking EXACTLY like that XSL-styled XML in web browser
Think again about this requirement. Paged media such as PDF and non-paged media such as HTML may only look "close enough", but never "exactly like" each other. This is even more obvious if you consider your HTML being displayed on devices with different screen sizes.
If you relax the above requirement somewhat, you'll probably agree that XSL-FO is the best choice. You definitely do not need to write "custom FO's for every file": write an XSLT just once, and use it on-the-fly to convert your XML to XSL-FO, and then use a rendering engine to process XSL-FO to PDF. Simple.
XSL-FO does sound like exactly what you need. But if that's not an option, first explicitly doing the XSLT transform on the XML in Java and then converting the resulting HTML (which by then is a String/byte array/DOM/whatever you want) to PDF using some additional library would do the trick. There's some libraries that support HTML to PDF, like iText for example. XSLT transformations in Java are really simple. Little code involved there.

need to convert pdf to xml or html using XSLT or through java code

Hi
I want to convert pdf to xml or html using xslt or through java code..please help me..Thanks in advance..
You cannot do these conversions in XSLT because XSLT requires XML as input, and PDF is not an XML-based format.
For PDF to HTML converters in Java, see answers to this SO Question. And this article recommends PDFBox.
There are also commercial tools around for exporting or converting PDFs as HTML or XML.

Categories

Resources