Solved

Adding style to XML documents using XSLT and possibly XSL:FO

Posted on 2009-03-29
5
281 Views
Last Modified: 2013-11-18
I am trying to add styles to my XML documents. In the past I have achieved this simply by including "style" and "class" attributes, and then copying those into the generated HTML.

I was considering adding CSS-like attributes to my XML elements (like in source below) to ease the transformation into formats such as PDF to avoid heavy processing on the "style" attribute. This should be easy to translate into HTML because I could simply concatenate all attributes within the "fx" namespace into a single "style" attribute.

From my searches on Google it seems as though XSL:FO is an absolute must for creating PDF files. I have never used FO before; is this what I need to use? If it is, how would I transform such "fx" styles from the source document?

Does Saxon support the XSL formatting objects?
<paragraph fx:text-align="center" fx:font-weight="bold">
   Bold text with center alignment.
</paragraph>

Open in new window

0
Comment
Question by:numberkruncher
  • 3
  • 2
5 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 24013557
XSL:FO is a good fit for creating PDF from XML. It is specially usefull for complex high quality print, and when you would need hyperlinks inside the PDF, for example.
If you are less demanding for the quality of the printed page, there is a lot you can do by transforming the XML to HTML and deal with some print specifics with CSS

XSL:FO is basically some sort of instruction set that specifies where everything fits the PDF page (the actual text is merged in the instructions) for allowing an XSL:FO processor to render the instructions to the page... FOP is an open source processor from the apache project. RenderX and Antenna House are commercial XS:FO processors.
Usualy one uses XSLT to merge the XML with the FO instructions to create the XSL:FO, but you don't have to.
XSL:FO processors come with a built in XSLT processor, for making the first step work.

I most often use Saxon to generate the XSL:FO, so I can use XSLT2 in its full glory to make that merge happen,
I only use the XSL:FO processor to do the actual FO to PDF rendering.

XSL:FO is quiet a different beast than CSS, and I believe you can get a lot of what you need doen, with simple CSS,
so unless you have demanding needs for the print pages, I would go for your fx:style approach and CSS.
That paradigm will map less good to XSL:FOP, so your XSLT will be a lot more complex

cheers

Geert
0
 
LVL 13

Author Comment

by:numberkruncher
ID: 24015599
I think that you are right, CSS should suit my needs for now.

Just to clarify:
    Step 1: XML document is transformed into XSL:FO using XSLT.
    Step 2: XSL:FO is then transformed into PDF using a processor like FOP.

If at a later stage I found myself needing XSL:FO, can I be assured that there is at least one way to simulate the of each of the CSS styles?

Thanks Geert!!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24016227
Your clarification
Step 1: yes, though you can use other means to create XSL:FO, other than XSLT (example pull the XSL:FO directly from a database, use scripting language ...)
Step 2: correct

XSL:FO is richer than CSS, so you would find an alternative for each style (other than the sound and pitch ones)
0
 
LVL 13

Author Comment

by:numberkruncher
ID: 24018831
Fantastic!

Thanks again Gertone for your excellent guidance!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24019025
welcome
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 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