Solved

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

Posted on 2009-03-29
5
278 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Fantastic!

Thanks again Gertone for your excellent guidance!
0
 
LVL 60

Expert Comment

by:Geert Bormans
Comment Utility
welcome
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

744 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

19 Experts available now in Live!

Get 1:1 Help Now