<?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"/>

    <xsl:template match="/data">
        <fo:root>
            <!-- <editor-fold desc="размеры страницы"> -->
            <fo:layout-master-set>
                <fo:simple-page-master master-name="invoice" 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>
            <!-- </editor-fold> -->
            <fo:page-sequence master-reference="invoice" id="invoice" initial-page-number="1" force-page-count="no-force" font-size="10pt" font-family="SegoeUI" linefeed-treatment="preserve">
                <!-- <editor-fold desc="повторяющийся футер"> -->
                <fo:static-content flow-name="xsl-region-after">
                    <!-- <editor-fold desc="таблица с реквизитами"> -->
                    <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>
                                            <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>
                                            <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>
                                            <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>
                                            <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>
                                            <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>
                                            <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>
                    <!-- </editor-fold> -->
                    <!-- <editor-fold desc="Номер страницы, если необходимо"> -->
                    <xsl:if test="ceiling(count(body/items/item)) > 25">
                        <fo:block-container line-height="1" text-align="right" width="40pt" height="12pt" absolute-position="absolute" bottom="0" right="0">
                            <fo:block>
                                <fo:inline>
                                    <fo:page-number ref-id="invoice"/>
                                </fo:inline>
                                <fo:inline>/</fo:inline>
                                <fo:inline>
                                    <fo:page-number-citation-last ref-id="invoice"/>
                                </fo:inline>
                            </fo:block>
                        </fo:block-container>
                    </xsl:if>
                    <!-- </editor-fold> -->
                </fo:static-content>
                <!-- </editor-fold> -->
                <!-- <editor-fold desc="Основное наполнение счета"> -->
                <fo:flow flow-name="xsl-region-body">
                    <!-- <editor-fold desc="Лого ALVADI"> -->
                    <fo:block>
                        <fo:external-graphic content-height="scale-to-fit" width="202pt">
                            <xsl:attribute name="src">
                                <xsl:value-of select="logo/src"/>
                            </xsl:attribute>
                        </fo:external-graphic>
                    </fo:block>
                    <!-- </editor-fold> -->
                    <!-- <editor-fold desc="Клиент"> -->
                    <fo:block-container width="220pt" margin="17pt 0 2pt 7pt">
                        <fo:block>
                            <fo:inline font-weight="bold" border-bottom="0.2pt solid black" padding-bottom="1pt">
                                <xsl:value-of select="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="header/customer/name"/>
                            </fo:block>
                        </fo:block>
                    </fo:block-container>
                    <!-- </editor-fold> -->
                    <!-- <editor-fold desc="Данные счета"> -->
                    <fo:block-container width="200pt" absolute-position="absolute" top="65.5pt" right="0">
                        <fo:table table-layout="fixed" width="100%" line-height="1.2">
                            <fo:table-column/>
                            <fo:table-column/>
                            <fo:table-body font-weight="bold" font-size="110%">
                                <fo:table-row>
                                    <fo:table-cell text-align="right">
                                        <fo:block>
                                            <xsl:value-of select="header/invoice/name"/>
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding-left="12pt">
                                        <fo:block>
                                            <xsl:value-of select="header/invoice/nr"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-body>
                        </fo:table>
                        <fo:table table-layout="fixed" width="100%">
                            <fo:table-column/>
                            <fo:table-column/>
                            <fo:table-body>
                                <fo:table-row>
                                    <fo:table-cell padding-bottom="2pt" text-align="right">
                                        <fo:block>
                                            <xsl:value-of select="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="header/invoice/date-creation"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-body>
                        </fo:table>
                    </fo:block-container>
                    <!-- </editor-fold> -->
                    <!-- <editor-fold desc="Таблица товаров" -->
                    <fo:table table-layout="fixed" width="100%" border-collapse="separate" border-separation="0" font-size="8pt">
                        <fo:table-column column-width="3%"/>
                        <fo:table-column column-width="13%"/>
                        <fo:table-column column-width="13%"/>
                        <fo:table-column column-width="31%"/>
                        <fo:table-column column-width="16%"/>
                        <fo:table-column column-width="11%"/>
                        <fo:table-column column-width="6%"/>
                        <fo:table-column column-width="7%"/>
                        <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="body/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="body/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="body/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="body/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="body/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="body/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="body/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="body/items/price"/>
                                </fo:block>
                            </fo:table-cell>
                        </fo:table-header>
                        <fo:table-body>
                            <xsl:choose>
                                <xsl:when test="ceiling(count(body/items/item)) > 0">
                                    <xsl:for-each select="body/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="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>
                                </xsl:when>
                                <xsl:otherwise>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                </xsl:otherwise>
                            </xsl:choose>
                        </fo:table-body>
                    </fo:table>
                    <!-- </editor-fold> -->
                    <!-- <editor-fold desc="Итоговая таблица"> -->
                    <fo:block border-top="0.5pt solid black">
                        <fo:table table-layout="fixed" width="100%" border-collapse="separate" margin-top="24pt" 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>
                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell font-weight="bold">
                                        <fo:block><xsl:value-of select="body/items/amount/counter-text"/>:
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell font-weight="bold">
                                        <fo:block>
                                            <xsl:value-of select="body/items/amount/counter"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block/>
                                    </fo:table-cell>
                                    <fo:table-cell font-weight="bold">
                                        <fo:block>
                                            <xsl:value-of select="body/items/amount/pay-text"/>
                                        </fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell font-weight="bold">
                                        <fo:block>
                                            <xsl:value-of select="body/items/amount/pay"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>
                    <!-- </editor-fold> -->

                    <!-- <editor-fold desc="Signature block"> -->
                    <fo:block margin-top="24pt" keep-together="always">
                        <fo:table table-layout="fixed" width="100%">
                            <fo:table-column column-width="40%"/>
                            <fo:table-column column-width="20%"/>
                            <fo:table-column column-width="40%"/>
                            <fo:table-body keep-together="auto">
                                <fo:table-row>
                                    <fo:table-cell number-columns-spanned="3" padding-bottom="24pt">
                                        <fo:block><xsl:value-of select="signature/intro"/></fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                                <fo:table-row>
                                    <fo:table-cell number-columns-spanned="3" padding-bottom="24pt">
                                        <fo:block margin-top="24pt" font-weight="bold"><xsl:value-of select="signature/date"/></fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                                <fo:table-row>
                                    <fo:table-cell padding-bottom="24pt" text-align="center">
                                        <fo:block><xsl:value-of select="signature/personA/name"/></fo:block>
                                        <fo:block margin-top="4pt" padding-top="4pt" border-top="0.2pt solid black" font-size="8pt"><xsl:value-of select="signature/personA/description"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding-bottom="24pt">
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding-bottom="24pt" text-align="center">
                                        <fo:block>&#0160;</fo:block>
                                        <fo:block margin-top="4pt" padding-top="4pt" border-top="0.2pt solid black" font-size="8pt"><xsl:value-of select="signature/personA/signText"/></fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                                <fo:table-row>
                                    <fo:table-cell padding-bottom="24pt" text-align="center">
                                        <fo:block><xsl:value-of select="signature/personB/name"/></fo:block>
                                        <fo:block margin-top="4pt" padding-top="4pt" border-top="0.2pt solid black" font-size="8pt"><xsl:value-of select="signature/personB/description"/></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding-bottom="24pt">
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell padding-bottom="24pt" text-align="center">
                                        <fo:block>&#0160;</fo:block>
                                        <fo:block margin-top="4pt" padding-top="4pt" border-top="0.2pt solid black" font-size="8pt"><xsl:value-of select="signature/personB/signText"/></fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-body>
                        </fo:table>
                    </fo:block>

                </fo:flow>
                <!-- </editor-fold> -->
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

</xsl:stylesheet>