XSL-FO Blocks (blokken)

De uitvoer van XSL-FO bevindt zich in de blokregio.

XSL-FO pagina's, stromen en blokken

De inhoud 'blokken' stromen in de 'pagina' en worden vervolgens naar het medium uitgevoerd.

De XSL-FO-uitvoer wordt meestal ingesloten in de <fo:block>-elementen, die ingesloten zijn in de <fo:flow>-elementen, die op hun beurt ingesloten zijn in de <fo:page-sequence>-elementen:

<fo:page-sequence>
  <fo:flow flow-name="xsl-region-body">
    <fo:block>
      <!-- Output goes here -->
    </fo:block>
  </fo:flow>
</fo:page-sequence>

Block area attributes

A block is a sequence of output located within a rectangular box:

<fo:block border-width="1mm">
There is a one-millimeter border around this output block.
</fo:block>

Since the block area is a rectangular box, it can share many common area attributes:

  • space before and space after
  • margin
  • border
  • padding
  • space before

Illustration:

space before and space after is the blank area that separates blocks from each other.

margin is the blank area outside the block.

border The rectangular area outside the outer edge of the area. Each of the four sides can have different widths. It can also be filled with different colors and background images.

padding is the area located between the content area and the border.

ContentThe area can contain actual content, such as text, images, graphics, etc.

block margin

  • margin
  • margin-top
  • margin-bottom
  • margin-left
  • margin-right

block border

border style attribute:

  • border-style
  • border-before-style
  • border-after-style
  • border-start-style
  • border-end-style
  • border-top-style (equivalent to border-before)
  • border-bottom-style (equivalent to border-after)
  • border-left-style (equivalent to border-start)
  • border-right-style (equivalent to border-end)

border color attribute:

  • border-color
  • border-before-color
  • border-after-color
  • border-start-color
  • border-end-color
  • border-top-color (equivalent to border-before)
  • border-bottom-color (equivalent to border-after)
  • border-left-color (等同于 border-start)
  • border-right-color (等同于 border-end)

边框宽度属性:

  • border-width
  • border-before-width
  • border-after-width
  • border-start-width
  • border-end-width
  • border-top-width (等同于 border-before)
  • border-bottom-width (等同于 border-after)
  • border-left-width (等同于 border-start)
  • border-right-width (等同于 border-end)

块填充

  • padding
  • padding-before
  • padding-after
  • padding-start
  • padding-end
  • padding-top (等同于 padding-before)
  • padding-bottom (等同于 padding-after)
  • padding-left (等同于 padding-start)
  • padding-right (等同于 padding-end)

块背景

  • background-color
  • background-image
  • background-repeat
  • background-attachment (scroll 或者 fixed)

块样式属性:

块是可被单独样式化的输出序列:

<fo:block
  font-size="12pt"
  font-family="sans-serif">
This block of output will be written in a 12pt sans-serif font.
</fo:block>

字体属性:

  • font-family
  • font-weight
  • font-style
  • font-size
  • font-variant

文本属性:

  • text-align
  • text-align-last
  • text-indent
  • start-indent
  • end-indent
  • wrap-option (定义自动换行,word wrap)
  • break-before (定义分页符,page breaks)
  • break-after (definieert paginabreuk, page breaks)
  • reference-orientation (definieert tekstrotatie binnen 90"}

Voorbeeld

<fo:block
    font-size="14pt" font-family="verdana" color="red"
    space-before="5mm" space-after="5mm">
W3School
</fo:block>
<fo:block
    text-indent="5mm"
    font-family="verdana" font-size="12pt"
    space-before="5mm" space-after="5mm">
Bij CodeW3C.com vind je alle webbouwtutorials die je
nodig, van basis HTML en XHTML tot geavanceerde XML, XSL, Multimedia
en WAP.
</fo:block>

Resultaat:

Zie het voorbeeld hierboven, om een document te genereren met veel titels en paragrafen, zal een grote hoeveelheid code nodig zijn.

Normaal gesproken combineren XSL-FO-documenten niet de formatteringsinformatie en inhoud zoals we net hebben gedaan.

Met een beetje hulp van XSLT kunnen we de formatteringsinformatie in sjablonen plaatsen en vervolgens schoner inhoud schrijven.

Je zult in de volgende hoofdstukken van deze handleiding leren hoe je XSLT-sjablonen kunt gebruiken om XSL-FO te combineren.