Выбрать главу

• <fo:table-and-caption>;

• <fo:table>;

• <fo:table-column>;

• <fo:table-caption>;

• <fo:table-header>;

• <fo:table-footer>;

• <fo:table-body>;

• <fo:table-row>;

• <fo:table-cell>.

Создание таблиц в XSL-FO аналогично их созданию в HTML. Вы создаете элемент <fo:table>, содержащий всю таблицу целиком, затем форматируете каждый столбец при помощи элемента <fo:table-column>. После чего вы создаете элемент <fo:table-body>, чтобы задать тело таблицы. Элемент <fo:table-body> содержит все элементы <fo:table-row>, каждый из которых создает строку таблицы. Каждый элемент <fo:table-row> содержит элементы <fo:table-cell>, в которых содержатся данные ячеек таблицы.

Следующий пример (листинг 11.4) демонстрирует работу с этими элементами. Приведенная таблица стилей XSLT преобразует planets.xml в документ XSL-FO, форматирующий данные планет в таблицу XSL-FO.

Листинг 11.4. tables.xsl

<?xml version="1.0"?>

<xsclass="underline" stylesheet

 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

 xmlns:fo="http://www.w3.org/1999/XSL/Format"

 version="1.0">

 <xsclass="underline" template match="PLANETS">

  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

   <fo:layout-master-set>

    <fo:simple-page-master master-name="page"

     page-height="400mm" page-width="300mm"

     margin-top="10mm" margin-bottom="10mm"

     margin-left="20mm" margin-right="20mm">

     <fo:region-body margin-top="0mm" margin-bottom="10mm"

      margin-left="0mm" margin-right="0mm"/>

     <fo:region-after extent="10mm"/>

    </fo:simple-page-master>

   </fo:layout-master-set>

   <fo:page-sequence master-name="page">

    <fo:flow flow-name="xsl-region-body">

     <fo:table>

      <fo:table-column column-width="30mm"/>

      <fo:table-column column-width="30mm"/>

      <fo:table-column column-width="30mm"/>

      <fo:table-column column-width="30mm"/>

      <fo:table-column column-width="30mm"/>

      <fo:table-column column-width="30mm"/>

      <fo:table-body>

       <fo:table-row>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Name

         </fo:block>

        </fo:table-cell>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Mass

         </fo:block>

        </fo:table-cell>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Day

         </fo:block>

        </fo:table-cell>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Radius

         </fo:block>

        </fo:table-cell>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Density

         </fo:block>

        </fo:table-cell>

        <fo:table-cell border-width="0.5mm">

         <fo:block font-size="18pt" font-weight="bold">

          Distance

         </fo:block>

        </fo:table-cell>

       </fo:table-row>

       <xsclass="underline" apply-templates/>

      </fo:table-body>

     </fo:table>

    </fo:flow>

   </fo:page-sequence>

  </fo:root>

 </xsclass="underline" template>

 <xsclass="underline" template match="PLANET">

  <fo:table-row>

   <xsclass="underline" apply-templates/>

  </fo:table-row>

 </xsclass="underline" template>

 <xsclass="underline" template match="NAME">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

 <xsclass="underline" template match="MASS">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

 <xsclass="underline" template match="DAY">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

 <xsclass="underline" template match="RADIUS">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

 <xsclass="underline" template match="DENSITY">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

 <xsclass="underline" template match="DISTANCE">

  <fo:table-cell border-width="0.5mm">

   <fo:block font-size="18pt">

    <xsclass="underline" value-of select='.'/>

   </fo:block>

  </fo:table-cell>

 </xsclass="underline" template>

</xsclass="underline" stylesheet>

Вот результат после преобразования в документ XSL-FO (листинг 11.5).

Листинг 11.5. tables.fo

<?xml version="1.0" encoding="UTF-8"?>

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

 <fo:layout-master-set>

  <fo:simple-page-master margin-right="20mm" margin-left="20mm"

   margin-bottom="10mm" margin-top="10mm" page-width="300mm"

   page-height="400mm" master-name="page">

   <fo:region-body margin-right="0mm" margin-left="0mm"

    margin-bottom="10mm" margin-top="0mm"/>