Solved

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

Posted on 2009-03-29
5
283 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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Randomize in Owl Carousel v1.3.2 6 134
migrating to phpbb forum from vBulletin 4.2 3 97
PHP delete contents of file- before writing to it 6 73
Load XML element 3 43
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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…
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 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 …

752 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