Solved

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

Posted on 2009-03-29
5
284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

615 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