Appendix A. How Do I Do That?

CONTENTS

This appendix covers some of the common questions that are asked about XSL-FO, but are not answered by the Recommendation. Usually someone has thought about it and found an answer by using (or misusing, depending on your point of view) one aspect or another of the Recommendation.

I'm used to using <xsl:preserve-space> to keep my whitespace in XSLT. Why doesn't it work in XSL-FO?

This is a case of working in the right domain. The xsl:* elements control spaces in the resulting XSL-FO file only; these hints don't even arrive at the formatter.

Whitespace handling in XSL-FO is controlled by a substantial set of specialized properties: space-treatment , linefeed-treatment, white-space-collapse , wrap-option, and white-space (a CSS2-compatibility shorthand).

I can't find a particular property on a particular element.

Note that not all properties are listed for all elements. Often the Recommendation will list them by some form of abstraction, such as border properties. This means that it's necessary to go hunting to find out if the property is available. Often, it is quicker to try it and see if it is supported by your formatter. Another option is to use the DTD provided by RenderX, and see if the fo file will validate to it. This is not guaranteed to work, but is very helpful. It does mean working in the fo namespace, but that often provides the answer that you can take back to the XSLT domain.

Can I create a newspaper-style layout: part of the page with one column, the rest with multiple columns?

Simply put, no. The present Recommendation focuses on content-driven layout, not layout-driven formatting. The former simply pours the content into predefined areas, the latter dictates where the content should go. It is a known issue that I hope will be addressed in the next version of the Recommendation.

Presently, you can fix this by using tables for layout, as in HTML, but don't expect content to wrap from one fake column to another.

How do I fix the position of some content?

Document appearance may change because of varying content. If you need to fix the position of content (perhaps the signature line on a letter at the bottom of the page), make use of the absolute-position property to ensure that the content appears where you want it. Remember that absolute positions are calculated with respect to the containing block, not the page. Example A-1 gives an example of this.

Example A-1. Fixed-position blocks
       <fo:block-container [1]       absolute-position="fixed" [2]              top="200mm">   <fo:block>Yours sincerely:     <fo:inline font-style="italic">Dave Pawson</fo:inline>   </fo:block> </fo:block-container>
  1. The absolute-position property ensures that content in this block is fixed.

  2. This block is fixed 200mm from the top.

How can I center a block across the page for instance, a table?

You can indent the table by half the width of the item, as in:

<fo:block width="4in" start-indent="(100% - 4in) div 2">  <xsl:apply-content/> </fo:block>

This provides a block of 4 inches, indented by half that value. If you have a mathematical bent, please realize that the formatter can deal with start-indent.

How do I number my footnotes consistently and automatically?

XSLT addresses this. If you want footnotes to be numbered automatically within, say, a chapter, use the xsl:number attributes (count, format, and level) to select the numbering system. For example:

<xsl:number count="footnote" from="chapter" format="i"/>

This will count all footnotes within a chapter, numbering them with lowercase Roman numerals.

How do I get text to spread out over the line, creating the appearance of left- and right- justified text?

You can achieve this by using a leader-pattern of space, as in the following example. The lefthand text is separated from the righthand text by means of the leader, which being formed of whitespace, does not show.

<fo:block text-align-last="justify">   Left-hand text   <fo:leader leader-pattern="space" />   Right-hand text </fo:block>
How do I start page numbering at something other than 1?

You can specify the number at which page numbering begins with:

<fo:page-sequence initial-page-label="A">

This specifies that all the pages in this sequence should be numbered starting at 42. Specify this in the page layout and specification section of the stylesheet. This can also be used to reset the page number to one, where it would normally (by default) continue numbering from the previous page sequence, simply by specifying the initial-page-number as 1.

What happens if I want to say page 42 of 120, where I don't know the last page number of the document?

In this case, you need to have a marker of some description at the end of the document. This is done by putting an empty block as the last item of content right at the end of the document and providing an id attribute on that block. Then you can use:

<fo:page-number-citation ref-id="theEnd"/> ... <fo block id="theEnd"></fo:block> 

which the formatter then replaces with the page number of the very last page.

How do I number my front matter pages using Roman numerals?

For the page master in question, use the format attribute to specify that Roman numerals are wanted:

<fo:page-sequence master-name="frontmatter" format="i">
How do I use a prefix for page numbering?

The prefix is a literal string, so add it as you would any other literal, for example, in Appendix C, to have the page numbers use the C prefix, try

<fo:static-content  flow-name="xsl-region-after">  <fo:block text-align="outside">C<fo:page-number/></fo:block>  </fo:static-content>

If you need the prefix calculated automatically, use the XSLT functions for numbering, with Arabic format, i.e. count the number of appendixes and format the number using the format attribute.

How do I get running headers where the chapter title is placed in the header?

Use the marker element, as in:

<fo:marker marker-class-name="rh"><xsl:value-of select="title"/> </fo:marker>

This must be in the block containing the chapter, normally a wrapper for the whole chapter. This is within the template for chapter. Then, in the static content for the header, use the marker, like so:

<fo:static-content flow-name="xsl-region-before">  <fo:block font=" 10pt Helvetica">  <fo:retrieve-marker retrieve-marker-name="rh"  retrieve-boundary="page"  retrieve-position="first-starting-within-page"/>  </fo:block> </fo:static-content>

This puts the chapter title on each page, and it changes as new chapters are formatted.

How do I create superscript and subscript?

The Recommendation specifically provides for this, either at the character level using:

< fo:character  character="1"  baseline-shift="super"  font-family="'MS Serif'"/>

which provides the number 1 in superscript (subscript is similar), or, as a standard inline, using:

<fo:inline  vertical-align="sub"  font-size="8pt"> <xsl:apply-templates/> </fo:inline> 

which takes any content within the inline and formats it as subscript.

How do I keep two pieces of content together (on the same page, column, etc.)?

There is a property that may be applied very broadly that ties content (in terms of blocks, lists, tables, inlines, etc.) together. It's named keep-with-*, where * can be previous or next. This uses the dot notation to provide a family of properties, such as keep-with-next.within-page and keep-with-previous.within-line. This set of properties are known as the keep properties. So, to keep a heading on the same page as the first paragraph, when styling the heading, try:

<fo:block  ... other properties keep-with-next.within-page='5'> <xsl:apply-contents/> </fo:block>

This tells the formatter that this and the following block should be kept together. The default value for this property is always. It can be set to either a number or always. The always value is the strongest way of expressing your need to keep these items together, even if it means starting a new page, for instance.

CONTENTS


XSL-FO
Xsl Fo
ISBN: 0596003552
EAN: 2147483647
Year: 2002
Pages: 24
Authors: Dave Pawson

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