Creating Columns

Creating Columns

Another useful way of using XSL-FO to format text is to use columns . Creating columns is not difficult; all you have to do is to use the column-count and column-gap properties of the <fo:region-body> element and leave the rest up to the XSL-FO processor.

Look at the following example, columns.fo. To format text into two columns with a gap of a quarter of an inch between them, I just set the column-count property to 2 and the column-gap property to 0.25in:

 <?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 margin-right="20mm" margin-left="20mm"              margin-bottom="10mm" margin-top="10mm" page-width="300mm"              page-height="400mm" master-name="page">              <fo:region-body margin-top="3cm" margin-bottom="2cm"                  column-count="2" column-gap="0.25in"/>              <fo:region-before extent="3cm"/>              <fo:region-after extent="2cm"/>          </fo:simple-page-master>      </fo:layout-master-set>          .          .          . 

All thats left is to add some sample text to display in the columns; note that Im also using the <fo:static-content> element to create a headermore on <fo:static-content> in the following section:

Listing 12.7 columns.fo
 <?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 margin-right="20mm" margin-left="20mm"              margin-bottom="10mm" margin-top="10mm" page-width="300mm"              page-height="400mm" master-name="page">              <fo:region-body margin-top="3cm" margin-bottom="2cm"                  column-count="2" column-gap="0.25in"/>              <fo:region-before extent="3cm"/>              <fo:region-after extent="2cm"/>          </fo:simple-page-master>      </fo:layout-master-set>      <fo:page-sequence master-name="page">          <fo:static-content flow-name="xsl-region-before">              <fo:block text-align="center" font-size="36pt"                  font-family="sans-serif"                  line-height="48pt" >                  Creating Columns              </fo:block>          </fo:static-content>          <fo:flow flow-name="xsl-region-body">          <fo:block font-size="24pt" font-family="sans-serif" space-after="15pt">                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.                  Sample Text. Sample Text. Sample Text. Sample Text. Sample Text.              </fo:block>          </fo:flow>      </fo:page-sequence>  </fo:root> 

You can see the results of this document, columns.pdf, in Figure 12.7.

Figure 12.7. Creating columns using XSL-FO.
graphics/12fig07.gif


Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

Similar book on Amazon

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