Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-03-29
5
Medium Priority
?
294 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

971 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