Chapter 14. XSL Formatting Objects

In the previous chapter, we took a look at the XSL transformation language. In this chapter, we'll take a look at the second half of XSL: formatting objects.

The World Wide Web Consortium (W3C) has defined formatting objects as root , block , and character that support different properties such as font-weight , line-height , and border . Using these predefined objects, you can specify the exact formatting for a document. At the time of this writing, there are 56 formatting objects and 177 properties that apply to these objects. Each of these objects has its own XML tag, and the properties it supports are attributes of that tag (many of these properties come from CSS2).

Like other XML applications, XSL formatting objects have their own namespace, http://www.w3.org/1999/XSL/Format , and the namespace prefix people use for that namespace is almost invariably fo for formatting objects. For example, here's how I can create a block (recall from CSS that blocks are rectangular areas in the output document) that displays the text Welcome to XSL formatting . in 36-point sans-serif font using the <fo:block> formatting object:

 <fo:block font-family="sans-serif" line-height="48pt" font-size="36pt">      Welcome to XSL formatting. </fo:block> 

The formatting object I'm using here is fo:block , and the properties I'm assigning values to are font-family , line-height , and font-size . After you've created a document using the XSL formatting objects, you can let an XSL processor format that document. We'll see one such program in this chapter that creates PDF (Portable Document Format, the common format you see on the Web for document exchange) files from documents written with the XSL formatting objects.

That's the idea: If you write your documents using the formatting objects, you can actually specify how that document will be displayed, down to the last comma and figure. Unfortunately, very little software actually interprets and uses the XSL formatting objects yet. In this chapter, we'll use the only such package I know of: the Apache XML project's fop processor.

The <fo:block> formatting object and all the others are defined by the W3C; you can find the W3C recommendation for the XSL formatting objects at www.w3.org/TR/xsl. The specification for all the formatting objects is at www.w3.org/TR/xsl/slice6.html, and the specification of the properties you can use with these objects is at www.w3.org/TR/xsl/slice7.html.

For More Info on Formatting Objects

We can't cover the entire field of formatting objects here because that would take a book by itself. For all the details, make sure you refer to www.w3.org/TR/xsl.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net