Home arrow XML arrow Page 4 - Using XSL Formatting Objects
XML

Using XSL Formatting Objects


If you need to format content not just for web pages, but for pages that will actually be printed out, keep reading. There is a technology called XSL Formatting Objects that can help you get the job done. In this article, we'll explain how to use it to format your content appropriately.

Author Info:
By: Peyton McCullough
Rating: 4 stars4 stars4 stars4 stars4 stars / 7
February 04, 2009
TABLE OF CONTENTS:
  1. · Using XSL Formatting Objects
  2. · Creating a Hello world document
  3. · Processing a document
  4. · Page masters

print this article
SEARCH DEVARTICLES

Using XSL Formatting Objects - Page masters
(Page 4 of 4 )

Let's explore XSL-FO in more detail, starting with page masters. As mentioned earlier, page masters govern the geometry of pages. Pages created from content within a page-sequence element that references a given page master will use the page master's properties.

In the first example, the text "Hello, world." was crammed into the top left-hand corner of the document, flush with the edge of the page. This is very unappealing. In order to fix this, we need to add some margins to the page. Before we do that, though, it helps to determine the size of the page itself. This can be done by setting the page-height and page-width attributes of the simple-page-master element. Let's create a letter-sized page (8.5" x 11") by modifying the simple-page-master element within helloworld.fo:


<fo:simple-page-master master-name="BasicPage" page-width="8.5in" page-height="11in">


With the page's dimensions defined, we can now set some margins. There are a few ways we can do this. The first is to define the margins uniformly, giving each side of the page the same margin. This can be done using the margin attribute. Let's make the page have a margin of one inch on all sides:


<fo:simple-page-master master-name="BasicPage" page-width="8.5in" page-height="11in" margin="1in">


Another way way is to set the margins individually. Margins for each side can be set using the margin-top, margin-bottom, margin-left and margin-right attributes. Suppose we wanted to specify margins of one inch on the top and the bottom and margins of three-quarters of an inch on the left and right. We'd do it like this:


<fo:simple-page-master master-name="BasicPage" page-width="8.5in" page-height="11in" margin-top="1in" margin-bottom="1in" margin-left=".75in" margin-right=".75in">


The above markup is a bit lengthy though. It's also possible to set the margins individually with the margin attribute. Margin sizes for each side can be passed in, separated by whitespace, just as they can with HTML. We can accomplish the same thing as above like this:


<fo:simple-page-master master-name="BasicPage" page-width="8.5in" page-height="11in" margin="1in .75in 1in .75in">


The first measurement passed in is the top margin. From there, it moves clockwise, so that the second measurement is the right margin, and so forth. We can simplify the above code even more, though. If we just pass in two measurements, then the first measurement will be used for the top and bottom margins, and the second measurement will be used for the left and right margins. The following markup would produce the same output:


<fo:simple-page-master master-name="BasicPage" page-width="8.5in" page-height="11in" margin="1in .75in">


Text isn't simply thrown onto the page in the same area, though. Later, we'll cover regions. Thanks for reading!


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus
XML ARTICLES

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials