Creating Tables

Some of the most useful constructs that you can format with XSL are tables. A table in XSL is much like one in HTMLa rectangular grid of rows and columns of cells . You can use nine formatting objects to create tables:

  • fo:table-and-caption

  • fo:table

  • fo:table-column

  • fo:table-caption

  • fo:table-header

  • fo:table-footer

  • fo:table-body

  • fo:table-row

  • fo:table- cell

Creating tables is a little involved in XSL. You create a fo:table object and then format each column with a fo:table-column object. Then you create a table-body object , as well as table-row objects for each row and table-cell objects for each cell in each row. Here's an example creating a 3x3 table with the words Tic , Tac , and Toe repeated on each line:

Listing ch14_08.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="20mm"             margin-top="20mm" page-width="300mm"             page-height="400mm" master-name="page">             <fo:region-body margin-right="0mm" margin-left="0mm"                 margin-bottom="20mm" margin-top="0mm"/>             <fo:region-after extent="20mm"/>         </fo:simple-page-master>     </fo:layout-master-set>     <fo:page-sequence master-reference="page">         <fo:flow flow-name="xsl-region-body">             <fo:table width="12cm" table-layout="fixed">                 <fo:table-column column-number="1" column-width="25mm">                 </fo:table-column>                 <fo:table-column column-number="2" column-width="25mm">                 </fo:table-column>                 <fo:table-column column-number="3" column-width="25mm">                 </fo:table-column>                 <fo:table-body>                      <fo:table-row line-height="20mm">                          <fo:table-cell column-number="1">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tic                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="2">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tac                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="3">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Toe                              </fo:block>                          </fo:table-cell>                      </fo:table-row>                      <fo:table-row line-height="20mm">                          <fo:table-cell column-number="1">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tic                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="2">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tac                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="3">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Toe                              </fo:block>                          </fo:table-cell>                      </fo:table-row>                      <fo:table-row line-height="20mm">                          <fo:table-cell column-number="1">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tic                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="2">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Tac                              </fo:block>                          </fo:table-cell>                          <fo:table-cell column-number="3">                              <fo:block font-family="sans-serif"                                  font-size="36pt">                                  Toe                              </fo:block>                          </fo:table-cell>                      </fo:table-row>                </fo:table-body>             </fo:table>         </fo:flow>     </fo:page-sequence> </fo:root> 

Running this file, ch14_08.fo, through fop creates ch14_09.pdf, which you can see in Figure 14-3.

Figure 14-3. An XSL-formatted table in Adobe Acrobat.

graphics/14fig03.gif

I'll take a look at the various objects you use to create tables now.



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