Input sample:
<doc> <chapter> <title>Chapter title</title> <section> <title>First section title</title> <paragraph>Section one's first paragraph.</paragraph> <paragraph>Section one's second paragraph.</paragraph> </section> <section> <title>Second section title</title> <paragraph>Section two's only paragraph.</paragraph> </section> </chapter> </doc>
In this example the chapter title appears at the top of the page (its "space-before" is discarded).
Space between chapter title and first section title is (8pt,8pt,8pt): the chapter title's "space-after" has a higher precedence than the section title's "space-before" (which takes on the initial value of zero), so the latter is discarded.
Space between the first section title and section one's first paragraph is (6pt,6pt,6pt): the section title's "space-after" has higher precedence than the paragraph's "space-before", so the latter is discarded.
Space between the two paragraphs is (6pt,8pt,10pt): the "space-after" the first paragraph is discarded because its precedence is equal to that of the "space-before" the next paragraph, and the optimum of the "space-after" of the first paragraph is greater than the optimum of the "space-before" of the second paragraph.
Space between the second paragraph of the first section and the title of the second section is (12pt,12pt,12pt): the "space-after" the paragraph is discarded because its precedence is equal to that of the "space-before" of the section title, and the optimum of the "space-after" of the paragraph is less than the optimum of the "space-before" of the section title.
The indent on the first line of the first paragraph in section one and the only paragraph in section two is zero; the indent on the first line of the second paragraph in section one is 2pc.
XSL Stylesheet:
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="chapter"> <fo:block break-before="page"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="chapter/title"> <fo:block text-align="center" space-after="8pt" space-before="16pt" space-after.precedence="3"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="section"> <xsl:apply-templates/> </xsl:template> <xsl:template match="section/title"> <fo:block text-align="center" space-after="6pt" space-before="12pt" space-before.precedence="0" space-after.precedence="3"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="paragraph[1]" priority="1"> <fo:block text-indent="0pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt"> <xsl:apply-templates/> </fo:block> </xsl:template> <xsl:template match="paragraph"> <fo:block text-indent="2pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt"> <xsl:apply-templates/> </fo:block> </xsl:template> </xsl:stylesheet>
Result Instance: elements and attributes in the fo: namespace:
<?xml version="1.0" encoding="utf-8"?> <fo:block break-before="page" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:block text-align="center" space-after="8pt" space-before="16pt" space-after.precedence="3">Chapter title</fo:block> <fo:block text-align="center" space-after="6pt" space-before="12pt" space-before.precedence="0" space-after.precedence="3">First section title</fo:block> <fo:block text-indent="0pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt">Section one's first paragraph.</fo:block> <fo:block text-indent="2pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt">Section one's second paragraph.</fo:block> <fo:block text-align="center" space-after="6pt" space-before="12pt" space-before.precedence="0" space-after.precedence="3">Second section title</fo:block> <fo:block text-indent="0pc" space-after="7pt" space-before.minimum="6pt" space-before.optimum="8pt" space-before.maximum="10pt">Section two's only paragraph.</fo:block> </fo:block>