XML
  Home arrow XML arrow Page 2 - Using XSL Formatting Objects
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

Using XSL Formatting Objects
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-02-04

    Table of Contents:
  • Using XSL Formatting Objects
  • Creating a Hello world document
  • Processing a document
  • Page masters

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using XSL Formatting Objects - Creating a Hello world document


    (Page 2 of 4 )

    Let's get started writing an XSL-FO document, one that simply places the text "Hello, world." on a page. Call the document helloworld.fo (.fo is the typical file extension for XSL-FO). The root element for an XSL-FO document is called root, and the typical namespace prefix for XSL-FO elements is fo. Let's go ahead and create the root element, along with the namespace declaration and the XML declaration:


    <?xml version="1.0" encoding="UTF-8"?>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

    </fo:root>


    Next, we need to define a "page master," a type of formatting object which can be thought of as a page template. A page master specifies a page's geometry, such as its size and margins. We'll get into more detail later on. For now, let's just create a minimal page master. All masters are contained within the layout-master-set element:


    <fo:layout-master-set>

    </fo:layout-master-set>


    To create an individual page master, we'll need to create a simple-page-master element. Page masters must be named using the name attribute. Let's create a page master named "BasicPage":


    <fo:simple-page-master master-name="BasicPage">

    </fo:simple-page-master>


    A page can be divided into regions, which contain the content of the page. So, in order to make way for content, we must create a region within the page master. This region must be given a name using the region-name attribute. There are several elements available to create regions. We'll be using the region-body element because we want to place content in the body of the page. Let's create this element, and let's name the region "Body":


    <fo:region-body region-name="Body" />


    Now we need to add some content. To create a page, we need to create a page-sequence element, which must be a child of the root element. The content contained within a page-sequence element will "flow" from one page to the next as needed. We need to set the master-reference attribute to point to the page master that we just created:


    <fo:page-sequence master-reference="BasicPage">

    </fo:page-sequence>


    To add content to the region we created, we need to use a flow element. The flow-name attribute of this element specifies the region of the page where the content will go. Below, we create a flow element, which goes inside of the page-sequence element:


    <fo:flow flow-name="Body">

    </fo:flow>


    Now we can add a "block" of content using the block element, and inside of the block, we can put "Hello, world.":


    <fo:block>Hello, world.</fo:block>


    The completed document should look like this:


    <?xml version="1.0" encoding="UTF-8"?>
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
        <fo:layout-master-set>
            <fo:simple-page-master master-name="BasicPage">
                <fo:region-body region-name="Body" />
            </fo:simple-page-master>
        </fo:layout-master-set>
        <fo:page-sequence master-reference="BasicPage">
            <fo:flow flow-name="Body">
                <fo:block>Hello, world.</fo:block>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>


    More XML Articles
    More By Peyton McCullough


     

    XML ARTICLES

    - 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
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek