Block spacing example

<?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>

When the above stylesheet is applied to the following document, spacing will resolve as described below the following document.

<chapter>
<title>Chapter title</title>
<section>
<title>First section title</title>
<para>Section one's first paragraph.</para>
<para>Section one's second paragraph.</para>
</section>
<section>
<title>Second section title</title>
<para>Section two's only paragraph.</para>
</section>
</chapter>

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 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 2pc; the indent on the first line of the second paragraph in section one is zero.