<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"><xsl:output method="xml" indent="yes"/>

  <!-- classes in xsl -->
  <!-- xsl:use-attribute-sets="NAME" -->
  <xsl:attribute-set name="link">
    <xsl:attribute name="color">#006FAE</xsl:attribute>
    <xsl:attribute name="font-weight">bold</xsl:attribute>
  </xsl:attribute-set>
  
  <xsl:attribute-set name="signature">
    <xsl:attribute name="border-top">0.2pt solid black</xsl:attribute>
    <xsl:attribute name="margin">0 4pt</xsl:attribute>
    <xsl:attribute name="padding-top">4pt</xsl:attribute>
  </xsl:attribute-set>

  <xsl:attribute-set name="uppercase">
    <xsl:attribute name="text-transform">uppercase</xsl:attribute>
  </xsl:attribute-set>


  <xsl:template match="/">
    <fo:root>

      <!-- размеры страницы -->
      <xsl:choose>
        <xsl:when test="data/link">
          <fo:layout-master-set>
            <fo:simple-page-master master-name="arve"
                                   page-height="297mm"
                                    page-width="210mm"
                                        margin="10mm">
              <fo:region-body region-name="xsl-region-body" margin-top="0mm" margin-bottom="28mm"/>
              <fo:region-before region-name="xsl-region-before" extent="0mm"/>
              <fo:region-after region-name="xsl-region-after" extent="25mm"/>
            </fo:simple-page-master>
          </fo:layout-master-set>
        </xsl:when>
        <xsl:otherwise>
         <fo:layout-master-set>
           <fo:simple-page-master master-name="arve"
                                  page-height="297mm"
                                   page-width="210mm"
                                       margin="10mm">
             <fo:region-body region-name="xsl-region-body" margin-top="0mm" margin-bottom="23mm"/>
             <fo:region-before region-name="xsl-region-before" extent="0mm"/>
             <fo:region-after region-name="xsl-region-after" extent="20mm"/>
           </fo:simple-page-master>
         </fo:layout-master-set>
        </xsl:otherwise>
      </xsl:choose>

      <!-- наполнение страниц -->
      <fo:page-sequence master-reference="arve" id="arve" initial-page-number="1" font-size="10pt" font-family="sans-serif" linefeed-treatment="preserve">

        <!-- повторяющийся футер -->
        <fo:static-content flow-name="xsl-region-after">
          <!-- таблица с реквизитами -->
          <fo:block border-top="0.2pt solid black" line-height="1.3" padding="8pt 0">
            <fo:table table-layout="fixed" width="100%">
              <fo:table-column column-width="26%"/>
              <fo:table-column column-width="12%"/>
              <fo:table-column column-width="28%"/>
              <fo:table-column column-width="9%"/>
              <fo:table-column column-width="24%"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col1/name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col2/address-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col2/address"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col3/iban-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col3/iban"/></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col1/reg-nr"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col2/phone-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col2/phone"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col3/bank-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col3/bank"/></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col1/vat"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col2/email-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col2/email"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block text-align="right" margin-right="4pt"><xsl:value-of select="data/footer/col3/swift-name"/></fo:block></fo:table-cell>
                  <fo:table-cell ><fo:block><xsl:value-of select="data/footer/col3/swift"/></fo:block></fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </fo:block>
          <!-- ссылка на оплату -->
          <xsl:if test="data/link">
            <fo:block>
              <fo:inline padding-right="8pt"><xsl:value-of select="data/link/name"/></fo:inline>
                <fo:basic-link xsl:use-attribute-sets="link">
                  <xsl:attribute name="external-destination">
                    <xsl:value-of select="data/link/url"/>
                  </xsl:attribute>
                  <xsl:value-of select="data/link/text"/>
                </fo:basic-link>
            </fo:block>
          </xsl:if>
          <!-- номер страницы -->
          <fo:block-container line-height="1" text-align="right" width="40pt" height="12pt" absolute-position="absolute" bottom="3pt" right="0">
            <fo:block><fo:page-number/>/<fo:page-number-citation-last ref-id="arve"/></fo:block>
          </fo:block-container>
        </fo:static-content>

        <!-- Основное наполнение счета -->
        <fo:flow flow-name="xsl-region-body">

          <!-- Лого ALVADI -->
          <fo:block>
            <fo:external-graphic content-height="scale-to-fit" width="202pt">
              <xsl:attribute name="src">
                <xsl:value-of select="data/logo/src"/>
              </xsl:attribute>
            </fo:external-graphic>
          </fo:block>

          <!-- Клиент -->
          <fo:block-container width="220pt" margin="7pt 0 2pt 7pt">
            <fo:block>
              <fo:inline font-weight="bold" border-bottom="0.2pt solid black" padding-bottom="1pt"><xsl:value-of select="data/header/customer/title"/></fo:inline>
            </fo:block>
            <fo:block margin="14pt 0 12pt 0">
              <fo:block margin-bottom="4pt" font-weight="bold"><xsl:value-of select="data/header/customer/name"/></fo:block>
              <fo:block margin-bottom="4pt" ><xsl:value-of select="data/header/customer/address"/></fo:block>
              <fo:block margin-bottom="4pt" ><xsl:value-of select="data/header/customer/phone"/></fo:block>
            </fo:block>
            <fo:block margin-left="-3pt">
              <fo:table table-layout="fixed" width="100%">
                <fo:table-column column-width="36%"/>
                <fo:table-column column-width="64%"/>
                <fo:table-body>
                  <fo:table-row>
                    <fo:table-cell><fo:block><xsl:value-of select="data/header/customer/reg-name"/></fo:block></fo:table-cell>
                    <fo:table-cell><fo:block><xsl:value-of select="data/header/customer/reg-nr"/></fo:block></fo:table-cell>
                  </fo:table-row>
                  <fo:table-row>
                    <fo:table-cell><fo:block><xsl:value-of select="data/header/customer/vat-name"/></fo:block></fo:table-cell>
                    <fo:table-cell><fo:block><xsl:value-of select="data/header/customer/vat-nr"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </fo:table-body>
              </fo:table>
            </fo:block>
          </fo:block-container>

          <!-- Данные счета -->
          <fo:block-container width="172pt" absolute-position="absolute" top="55.5pt" right="0">
            <fo:table table-layout="fixed" width="100%" line-height="1.2">
              <fo:table-column column-width="42%"/>
              <fo:table-column column-width="58%"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell text-align="right"><fo:block><xsl:value-of select="data/header/invoice/name"/></fo:block></fo:table-cell>
                  <fo:table-cell padding-left="12pt"><fo:block font-weight="bold"><xsl:value-of select="data/header/invoice/nr"/></fo:block></fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
            <fo:block border-bottom="0.2pt solid black" width="100%" margin-bottom="8pt"></fo:block>
            <fo:table table-layout="fixed" width="100%">
              <fo:table-column column-width="42%"/>
              <fo:table-column column-width="58%"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell padding-bottom="2pt" text-align="right"><fo:block><xsl:value-of select="data/header/invoice/name-date-creation"/></fo:block></fo:table-cell>
                  <fo:table-cell padding-bottom="2pt" padding-left="12pt"><fo:block font-weight="bold"><xsl:value-of select="data/header/invoice/date-creation"/></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell padding-bottom="2pt" text-align="right"><fo:block><xsl:value-of select="data/header/invoice/name-date-payment"/></fo:block></fo:table-cell>
                  <fo:table-cell padding-bottom="2pt" padding-left="12pt"><fo:block font-weight="bold"><xsl:value-of select="data/header/invoice/date-payment"/></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell padding-bottom="2pt" text-align="right"><fo:block><xsl:value-of select="data/header/invoice/name-reference-nr"/></fo:block></fo:table-cell>
                  <fo:table-cell padding-bottom="2pt" padding-left="12pt"><fo:block font-weight="bold"><xsl:value-of select="data/header/invoice/reference-nr"/></fo:block></fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </fo:block-container>

          <!-- Штрихкод и заглавие -->
          <fo:block text-align="center" margin="10pt 0">
            <xsl:if test="data/body/heading">
              <fo:block margin="10pt 0 2pt 0"><xsl:value-of select="data/body/heading"/></fo:block>
            </xsl:if>
<!--             <xsl:if test="data/body/barcode">
              <fo:block margin-bottom="10pt">
                <fo:external-graphic content-height="scale-to-fit" width="237pt">
                  <xsl:attribute name="src">
                    <xsl:value-of select="data/body/barcode"/>
                  </xsl:attribute>
                </fo:external-graphic>
              </fo:block>
            </xsl:if> -->
            <xsl:if test="data/body/barcode">
              <xsl:variable name="barcode"><xsl:value-of select="data/body/barcode"/></xsl:variable>
              <fo:block>
                <fo:instream-foreign-object>
                  <barcode:barcode xmlns:barcode="http://barcode4j.krysalis.org/ns" message="{$barcode}" orientation="0">
                    <barcode:code128>
                      <barcode:height>10mm</barcode:height>
                      <barcode:module-width>0.34mm</barcode:module-width>
                      <barcode:human-readable>none</barcode:human-readable>
                      <barcode:quiet-zone enabled="true">14mw</barcode:quiet-zone>
                    </barcode:code128>
                  </barcode:barcode>
                </fo:instream-foreign-object>
              </fo:block>
            </xsl:if>
          </fo:block>

          <!-- Таблица с компонентами счета simple -->
          <xsl:if test="data/items/type='simple'">
            <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="2pt" font-size="8pt">
              <fo:table-column column-width="14%"/>
              <fo:table-column column-width="50%"/>
              <fo:table-column column-width="10%"/>
              <fo:table-column column-width="14%"/>
              <fo:table-column column-width="12%"/>
              <fo:table-header font-weight="bold">
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/code"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/name"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="data/items/quantity"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/price"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/sum"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
              </fo:table-header>
              <fo:table-body>
                <xsl:for-each select="data/items/item">
                  <fo:table-row>
                    <fo:table-cell padding="2pt 0" font-weight="bold"><fo:block><xsl:value-of select="code"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" >
                      <fo:block><xsl:value-of select="name"/></fo:block>
                      <!-- Пометка о спецзаказе -->
                      <xsl:if test="special-link">
                        <fo:block font-style="italic" font-weight="bold">
                          <fo:inline><!-- <xsl:value-of select="code"/> --><xsl:value-of select="special-link/name"/></fo:inline>
                          <fo:basic-link xsl:use-attribute-sets="link">
                            <xsl:attribute name="external-destination">
                              <xsl:value-of select="special-link/url"/>
                            </xsl:attribute>
                            <xsl:value-of select="special-link/text"/>
                          </fo:basic-link>
                        </fo:block>
                      </xsl:if>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="quantity"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="price"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="sum"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </xsl:for-each>
              </fo:table-body>
            </fo:table>
          </xsl:if>
          <!-- Таблица с компонентами счета simple со скидкой -->
          <xsl:if test="data/items/type='discount'">
            <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="2pt" font-size="8pt">
              <fo:table-column column-width="14%"/>
              <fo:table-column column-width="36%"/>
              <fo:table-column column-width="10%"/>
              <fo:table-column column-width="17%"/>
              <fo:table-column column-width="13%"/>
              <fo:table-column column-width="10%"/>
              <fo:table-header font-weight="bold">
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/code"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/name"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="data/items/quantity"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/price"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/discount"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/sum"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
              </fo:table-header>
              <fo:table-body>
                <xsl:for-each select="data/items/item">
                  <fo:table-row>
                    <fo:table-cell padding="2pt 0" font-weight="bold"><fo:block><xsl:value-of select="code"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" >
                      <fo:block><xsl:value-of select="name"/></fo:block>
                      <xsl:if test="../cause">
                        <fo:block font-weight="bold"><xsl:value-of select="../cause"/>&#160;<xsl:value-of select="cause"/></fo:block>
                      </xsl:if>
                    </fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="quantity"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="price"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="discount"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="sum"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </xsl:for-each>
              </fo:table-body>
            </fo:table>
          </xsl:if>
          <!-- Таблица с компонентами счета acceptance -->
          <xsl:if test="data/items/type='acceptance'">
            <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="2pt" font-size="8pt">
              <fo:table-column column-width="14%"/>
              <fo:table-column column-width="72%"/>
              <fo:table-column column-width="14%"/>
              <fo:table-header font-weight="bold">
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/code"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/name"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="data/items/quantity"/></fo:block></fo:table-cell>
              </fo:table-header>
              <fo:table-body>
                <xsl:for-each select="data/items/item">
                  <fo:table-row>
                    <fo:table-cell padding="2pt 0" font-weight="bold"><fo:block><xsl:value-of select="code"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="name"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="quantity"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </xsl:for-each>
              </fo:table-body>
            </fo:table>
          </xsl:if>
          <!-- Таблица с компонентами счета return -->
          <xsl:if test="data/items/type='return'">
            <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="2pt" font-size="8pt">
              <fo:table-column column-width="3%"/>
              <fo:table-column column-width="13%"/>
              <fo:table-column column-width="9%"/>
              <fo:table-column column-width="15%"/>
              <fo:table-column column-width="20%"/>
              <fo:table-column column-width="16%"/>
              <fo:table-column column-width="12%"/>
              <fo:table-column column-width="7%"/>
              <fo:table-column column-width="5%"/>
              <fo:table-header font-weight="bold">
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/nr"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/artikul"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="data/items/shipping-date"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/spare"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/car-model"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/sup-order"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0"><fo:block><xsl:value-of select="data/items/comment"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/quantity"/></fo:block></fo:table-cell>
                <fo:table-cell border-top="0.5pt solid black" border-bottom="0.5pt solid black" padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="data/items/price"/>,</fo:block><fo:block xsl:use-attribute-sets="uppercase"><xsl:value-of select="data/items/currency"/></fo:block></fo:table-cell>
              </fo:table-header>
              <fo:table-body>
                <xsl:for-each select="data/items/item">
                  <fo:table-row>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="nr"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" font-weight="bold"><fo:block><xsl:value-of select="artikul"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="center"><fo:block><xsl:value-of select="shipping-date"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="spare"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="car-model"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="sup-order"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" ><fo:block><xsl:value-of select="comment"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="quantity"/></fo:block></fo:table-cell>
                    <fo:table-cell padding="2pt 0" text-align="right"><fo:block><xsl:value-of select="price"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </xsl:for-each>
              </fo:table-body>
            </fo:table>
          </xsl:if>

          <!-- Итоговая таблица -->
          <xsl:if test="data/items/amount">
            <fo:block>
              <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="2pt" text-align="right" line-height="1.5" page-break-inside="avoid">
                <fo:table-column column-width="50%"/>
                <fo:table-column column-width="40%"/>
                <fo:table-column column-width="10%"/>
                <fo:table-body>
                  <xsl:if test="data/items/amount/sum-text">
                    <fo:table-row>
                      <fo:table-cell><fo:block></fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/sum-text"/>,&#160;<xsl:value-of select="data/items/currency"/>:</fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/sum"/></fo:block></fo:table-cell>
                    </fo:table-row>
                  </xsl:if>
                  <xsl:if test="data/items/amount/turnover-tax-text">
                    <fo:table-row>
                      <fo:table-cell><fo:block></fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/turnover-tax-text"/>,&#160;<xsl:value-of select="data/items/currency"/>:</fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/turnover-tax"/></fo:block></fo:table-cell>
                    </fo:table-row>
                  </xsl:if>
                  <xsl:if test="data/items/amount/vat-text">
                    <fo:table-row>
                      <fo:table-cell><fo:block></fo:block></fo:table-cell>
                      <fo:table-cell number-columns-spanned="2"><fo:block color="gray"><xsl:value-of select="data/items/amount/vat-text"/></fo:block></fo:table-cell>
                    </fo:table-row>
                  </xsl:if>
                  <xsl:if test="data/items/penalty">
                    <fo:table-row>
                      <fo:table-cell><fo:block></fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/penalty-text"/>:</fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/penalty"/></fo:block></fo:table-cell>
                    </fo:table-row>
                  </xsl:if>
                  <xsl:if test="data/items/amount/counter-text">
                    <fo:table-row>
                      <fo:table-cell><fo:block></fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/counter-text"/>:</fo:block></fo:table-cell>
                      <fo:table-cell><fo:block><xsl:value-of select="data/items/amount/counter"/></fo:block></fo:table-cell>
                    </fo:table-row>
                  </xsl:if>
                  <fo:table-row>
                    <fo:table-cell><fo:block></fo:block></fo:table-cell>
                    <fo:table-cell font-weight="bold"><fo:block><xsl:value-of select="data/items/amount/pay-text"/>,&#160;<xsl:value-of select="data/items/currency"/>:</fo:block></fo:table-cell>
                    <fo:table-cell font-weight="bold"><fo:block><xsl:value-of select="data/items/amount/pay"/></fo:block></fo:table-cell>
                  </fo:table-row>
                </fo:table-body>
              </fo:table>
            </fo:block>
          </xsl:if>

          <!-- подтверждение о получении наличных -->
          <xsl:if test="data/body/cash">
            <fo:table table-layout="fixed" width="100%" text-align="center" page-break-inside="avoid" margin="16pt 0">
              <fo:table-column column-width="18%"/>
              <fo:table-column column-width="14%"/>
              <fo:table-column column-width="12%"/>
              <fo:table-column column-width="34%"/>
              <fo:table-column column-width="22%"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell><fo:block text-align="right" font-weight="bold" margin-right="8pt"><xsl:value-of select="data/body/cash/text"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/cash/sum"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/cash/date"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/cash/name"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/cash/signature"/></fo:block></fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </xsl:if>

          <!-- Разнообразное текстовым наполнением -->
          <fo:block margin="24pt 0">
            <!-- идентификационный номер -->
            <xsl:if test="data/body/infoblock/reference-text">
              <fo:block font-weight="bold" margin="8pt 0">
                <fo:inline padding-right="8pt"><xsl:value-of select="data/body/infoblock/reference-text"/></fo:inline><fo:inline border="1pt dotted black" padding="8pt 4pt 4pt 4pt"><xsl:value-of select="data/body/infoblock/reference-nr"/></fo:inline>
              </fo:block>
            </xsl:if>
            <!-- ссылка на оплату -->
            <xsl:if test="data/link">
              <fo:block margin="8pt 0">
                <fo:inline padding-right="8pt"><xsl:value-of select="data/link/name"/></fo:inline>
                <fo:basic-link xsl:use-attribute-sets="link">
                  <xsl:attribute name="external-destination">
                    <xsl:value-of select="data/link/url"/>
                  </xsl:attribute>
                  <xsl:value-of select="data/link/text"/>
                </fo:basic-link>
              </fo:block>
            </xsl:if>
            <!-- текст с директивой -->
            <xsl:if test="data/body/infoblock/directive">
              <fo:block margin="8pt 0"><xsl:value-of select="data/body/infoblock/directive"/></fo:block>
            </xsl:if>
            <!-- текст с подсказкой для идентификационного номера -->
            <xsl:if test="data/body/infoblock/reference-hint">
              <fo:block margin="8pt 0" font-weight="bold"><xsl:value-of select="data/body/infoblock/reference-hint"/></fo:block>
            </xsl:if>
            <!-- текст с подтверждением -->
            <xsl:if test="data/body/infoblock/conformation">
              <fo:block margin="8pt 0"><xsl:value-of select="data/body/infoblock/conformation"/></fo:block>
            </xsl:if>
          </fo:block>

          <!-- Подписи акта приемов -->
          <xsl:if test="data/body/acceptance-signature">
            <fo:table table-layout="fixed" width="100%" text-align="center" page-break-inside="avoid" margin="16pt 0">
              <fo:table-column column-width="20%"/>
              <fo:table-column column-width="50%"/>
              <fo:table-column column-width="30%"/>
              <fo:table-body>
                <fo:table-row>
                  <fo:table-cell><fo:block padding-bottom="4pt"><xsl:value-of select="data/body/acceptance-signature/date"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block></fo:block></fo:table-cell>
                </fo:table-row>
                <fo:table-row>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/acceptance-signature/date-text"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/acceptance-signature/name"/></fo:block></fo:table-cell>
                  <fo:table-cell><fo:block xsl:use-attribute-sets="signature"><xsl:value-of select="data/body/acceptance-signature/signature"/></fo:block></fo:table-cell>
                </fo:table-row>
              </fo:table-body>
            </fo:table>
          </xsl:if>

          <!-- Благодарность -->
          <xsl:if test="data/body/gratitude">
            <fo:block text-align="center" font-size="14pt" font-weight="bold" line-height="1.5" margin-top="16pt"><xsl:value-of select="data/body/gratitude"/></fo:block>
          </xsl:if>
        </fo:flow>

      </fo:page-sequence>

    </fo:root>
  </xsl:template>
</xsl:stylesheet>