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 W3C has defined such 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 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 that it supports are attributes of that tag. (Many of these properties come from CSS2, which you can read more about in Chapter 9, "Cascading Style Sheets.")

Like other XML applications, XSL formatting objects have their own namespace, "http://www.w3.org/1999/XSL/Format", and the namespace prefix that 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 that I'm using here is fo:block, and the properties that 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 files in PDF format (portable document format, the common format that you see on the Web for document exchange) 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 that I know of: the Apache XML Project's FOP processor.

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

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

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.86.121