Formatting a catalog.

We now take the climbing catalog example with prices being added and incrementally create a series of PDF versions improving from one version to another.

exercise No. 67

A first PDF version of the catalog Create comment in forum

Q:

Write a XSL script to generate a starting version climbenriched.start.pdf.

A:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
    <fo:root font-size="10pt">
      <fo:layout-master-set>
        <fo:simple-page-master master-name="productPage"
          page-width="80mm" page-height="110mm" margin="5mm">
          <fo:region-body margin="15mm"/>
          <fo:region-before extent="10mm"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:apply-templates select="catalog/product" />
    </fo:root>
  </xsl:template>

  <xsl:template match="product">
    <fo:page-sequence master-reference="productPage">
      <fo:static-content flow-name="xsl-region-before">
        <fo:block font-weight="bold">
          <xsl:value-of select="title"/>
        </fo:block>
      </fo:static-content>
      <fo:flow flow-name="xsl-region-body">
        <xsl:apply-templates select="description/para"/>

        <fo:block>Price:<xsl:value-of select="@price"/></fo:block>
        <fo:block>Order no:<xsl:value-of select="@id"/></fo:block>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>

  <xsl:template match="para">
    <fo:block space-after="10px">
      <xsl:value-of select="."/>
    </fo:block>
  </xsl:template>

</xsl:stylesheet>

Header, page numbers and table formatting

Extend A first PDF version of the catalog by adding page numbers. The order number and prices shall be formatted as tables. Add a ruler to each page's head. The result should look like climbenriched.product.pdf

A:

Solution see catalog2fo.product.xsl.

A table of contents.

Each product description's page number shall appear in a table of contents together with the product's title as in climbenriched.toc.pdf.

A:

Solution see catalog2fo.toc.xsl.

A:

Solution see catalog2fo.toclink.xsl.

A final version.

Add the following features:

  1. Number the table of contents starting with page i, ii, iii, iv and so on. Start the product descriptions with page 1. On each page's footer a text page xx of yy shall be displayed. This requires the definition of an anchor id on the FO document's last page.

  2. Add PDF bookmarks by using XEP's FO extensions. This requires the namespace declaration xmlns:rx="http://www.renderx.com/XSL/Extensions" in the XSLT script's header.

The result may look like climbenriched.final.pdf. N.B.: It may take some effort to achieve this result. This effort is left to the interested participants.

A:

Solution see catalog2fo.toclink.xsl.