<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
    <xsl:template match="receipt_order">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="order" page-width="210mm" page-height="170mm">
                    <fo:region-body margin="10mm"/>
                    <fo:region-before extent="2mm"/>
                    <fo:region-after extent="0mm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="order">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block font-size="9pt" font-family="NewtonAm">
                        <xsl:apply-templates select="half"/>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
    <xsl:template match="half">
        <fo:block space-before="0.8cm">
            <fo:table border="0.1pt solid white" width="100%">
                <fo:table-column column-width="50%"/>
                <fo:table-column column-width="50%"/>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell>
                            <fo:block font-size="8pt" margin-right="3mm" width="100%">
                                <xsl:apply-templates select="left_side"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-size="8pt" margin-left="5mm" width="100%">
                                <xsl:apply-templates select="right_side"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template>
    <xsl:template match="left_side">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="arm | eng">
        <fo:block font-size="7pt">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="right_side">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="form">
        <fo:block text-align="right">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="line">
        <fo:block width="100%">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="header">
        <fo:block font-size="11pt" space-after="6mm" text-align="center">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="company">
        <fo:block font-size="11pt" space-after="4mm" text-align="center" width="100%" border-bottom="0.5pt solid black">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="document_title">
        <fo:block space-after="6mm">
            <fo:table border="0.1pt solid white">
                <fo:table-column/>
                <fo:table-column column-width="30%"/>
                <fo:table-header height="0.5cm">
                    <fo:table-row>
                        <fo:table-cell text-align="left">
                            <fo:block text-align="left" font-size="10pt">
                                <xsl:apply-templates select="prefix"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell text-align="center" border-bottom="0.5pt solid black">
                            <fo:block text-align="center" font-size="10pt" padding-top="2mm">
                                <xsl:apply-templates select="content"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-header>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="1em">
                            <fo:block/>
                        </fo:table-cell>
                        <fo:table-cell height="1em" padding-top="0pt">
                            <fo:block text-align="center">
                                <xsl:apply-templates select="tip"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template>
    <xsl:template match="header_field">
        <fo:block text-align="center" width="80%" space-before="3mm">
            <fo:table border="0.1pt solid white">
                <fo:table-column column-width="40%"/>
                <fo:table-column column-width="40%"/>
                <fo:table-column column-width="20%"/>
                <fo:table-body height="0.5cm">
                    <fo:table-row>
                        <fo:table-cell>
                            <fo:block text-align="right">
                                <xsl:apply-templates select="part1"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell border-bottom="0.5pt solid black">
                            <fo:block text-align="center" padding-top="2mm">
                                <xsl:apply-templates select="date"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block text-align="left" padding-top="2mm">
                                <xsl:apply-templates select="year"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template>
    <xsl:template match="field">
        <fo:block space-before="2mm" space-after="3mm">
            <fo:table border="0.1pt solid white">
                <fo:table-column/>
                <fo:table-column column-width="54%"/>
                <fo:table-column/>
                <fo:table-header height="0.5cm">
                    <fo:table-row>
                        <fo:table-cell text-align="left">
                            <fo:block text-align="left" font-size="9pt">
                                <xsl:apply-templates select="prefix"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell text-align="center" border-bottom="0.5pt solid black">
                            <fo:block text-align="center" font-size="9pt" padding-top="2mm">
                                <xsl:apply-templates select="content"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell>
                            <fo:block font-size="9pt">
                                <xsl:apply-templates select="postfix"/>
                            </fo:block>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-header>
                <fo:table-body>
                    <fo:table-row>
                        <fo:table-cell height="1em">
                            <fo:block/>
                        </fo:table-cell>
                        <fo:table-cell height="1em" padding-top="0pt">
                            <fo:block font-size="7pt">
                                <xsl:apply-templates select="tip"/>
                            </fo:block>
                        </fo:table-cell>
                        <fo:table-cell height="1em">
                            <fo:block/>
                        </fo:table-cell>
                    </fo:table-row>
                </fo:table-body>
            </fo:table>
        </fo:block>
    </xsl:template>
    <xsl:template match="tip">
        <fo:block text-align="center" font-size="7pt" space-before="4pt">
            <xsl:apply-templates/>
        </fo:block>
    </xsl:template>
    <xsl:template match="table">
        <fo:table border="0.5pt solid black" text-align="center" space-before="2mm" space-after="2mm">
            <fo:table-column column-width="23mm"/>
            <fo:table-column column-width="23mm"/>
            <fo:table-column column-width="23mm"/>
            <fo:table-column column-width="23mm"/>
            <fo:table-header>
                <fo:table-row>
                    <xsl:for-each select="head/cell">
                        <fo:table-cell padding="0.1cm 0.2cm 0.1cm 0.2cm" border="0.5pt solid black" display-align="center">
                            <fo:block text-align="center" font-size="8pt">
                                <xsl:apply-templates/>
                            </fo:block>
                        </fo:table-cell>
                    </xsl:for-each>
                </fo:table-row>
            </fo:table-header>
            <fo:table-body>
                <fo:table-row height="0.6cm">
                    <xsl:for-each select="body/cell">
                        <fo:table-cell padding="0.1cm 0.2cm 0.1cm 0.2cm"
                            border="0.5pt solid black" display-align="center">
                            <fo:block text-align="center" font-size="10pt">
                                <xsl:apply-templates/>
                            </fo:block>
                        </fo:table-cell>
                    </xsl:for-each>
                </fo:table-row>
            </fo:table-body>
        </fo:table>
    </xsl:template>
</xsl:stylesheet>
