<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:saxon="http://saxon.sf.net/"
xmlns:wdExtensions="java:com.whitedoc.xslt.extensions.WdExtensions"
exclude-result-prefixes="saxon wdExtensions">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="EDIFACT/ORDERS"/>
<xsl:apply-templates select="EANCOM/ORDERS"/>
</xsl:template>
<xsl:template match="ORDERS">
<xsl:variable name="supplierGLN" select="../UNB/UNB03/UNB0301"/>
<xsl:variable name="senderGLN" select="../UNB/UNB02/UNB0201"/>
<xsl:variable name="supplierUuid" select="{wdExtensions:getValueFromDictionary('a5390637-f3b5-49f3-b7f6-48132f6fe8bb', '7f9d20ab-71d8-45e0-9756-2887fd427cd6', $supplierGLN, 'f69ee017-1fb3-4ff1-a803-c4ade48ea65e')}"/>
<envelope templateUuid="579ba3f3-7e26-4c7a-845c-ffa0fdf78057" templateVersion="55809865-32df-4341-91b0-b8bc44451394">
<info>
<subject>Замовлення на постачання № <xsl:choose><!--Dlya MTI-->
<xsl:when test="../UNB/UNB02/UNB0201=4820140450000"><xsl:value-of select="BGM/BGM02/BGM0201"/></xsl:when>
<xsl:otherwise><xsl:value-of select="BGM/BGM02"/></xsl:otherwise>
</xsl:choose>
</subject>
<message>Оригінал замовлення</message>
</info>
<state>
<message/>
<date>
2021-02-03T12:22:52.709Z
</date>
<roleId>
</roleId>
</state>
<documents>
<document id="cd511754-cfd1-49a3-aae4-aab212d83cea">
<field name="NUMBER">
<xsl:choose><!--Dlya MTI-->
<xsl:when test="../UNB/UNB02/UNB0201=4820140450000"><xsl:value-of select="BGM/BGM02/BGM0201"/></xsl:when>
<xsl:otherwise><xsl:value-of select="BGM/BGM02"/></xsl:otherwise>
</xsl:choose>
</field>
<xsl:apply-templates select="DTM"/>
<xsl:apply-templates select="GROUP_2" mode="YC1"/>
<xsl:if test="GROUP_7/CUX/CUX01/CUX0102 and ../UNB/UNB03/UNB0301!='4829900003227'">
<field name="CURRENCY"><xsl:value-of select="GROUP_7/CUX/CUX01/CUX0102"/></field>
</xsl:if>
<xsl:choose>
<xsl:when test="GROUP_1/RFF/RFF01/RFF0102 and ../UNB/UNB02/UNB0201='4820086630009'">
<field name="INFO">№ акции: <xsl:value-of select="GROUP_1/RFF/RFF01/RFF0102"/></field>
</xsl:when>
<xsl:when test="../UNB/UNB02/UNB0201='4823060600005'">
<field name="INFO"><xsl:value-of select="FTX/FTX04/FTX0401"/>, <xsl:value-of select="FTX/FTX04/FTX0402"/>, <xsl:value-of select="FTX/FTX04/FTX0403"/></field>
</xsl:when>
</xsl:choose>
<xsl:apply-templates select="GROUP_2" mode="NAD"/>
<fieldgroup name="POSITION">
<xsl:choose>
<xsl:when test="../UNB/UNB03/UNB0301='4829900003227'">
<xsl:apply-templates select="GROUP_28" mode="LOREAL"/>
</xsl:when>
<xsl:when test="GROUP_28">
<xsl:apply-templates select="GROUP_28"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="GROUP_25"/>
</xsl:otherwise>
</xsl:choose>
</fieldgroup>
<field name="POSITIONSCOUNT"><xsl:value-of select="count(//GROUP_28)"/></field>
<field name="SUMORDEREDQUANTITY"><xsl:value-of select="sum(//QTY0102)"/></field>
</document>
</documents>
<flow>
<roles>
<role id="f9378c46-5dfe-484a-b985-5a157d238b5c" mailboxUuid="625d1530-8896-49a5-b53c-37e5ade5e750"/>
<role id="d59d8545-f1d2-4008-951f-2f43509d966e" mailboxUuid="{$supplierUuid}"/>
</roles>
</flow>
</envelope>
</xsl:template>
<xsl:template match="DTM">
<xsl:choose>
<xsl:when test="DTM01/DTM0101 = '137'">
<field name="DATE">
<xsl:value-of select="substring(DTM01/DTM0102, 7, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 5, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 1, 4)"/>
</field>
</xsl:when>
<xsl:when test="DTM01/DTM0101 = '2'">
<xsl:if test="string-length(DTM01/DTM0102) = '12'">
<field name="DELIVERYDATE">
<xsl:value-of select="substring(DTM01/DTM0102, 7, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 5, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 1, 4)"/>
</field>
</xsl:if>
<xsl:if test="string-length(DTM01/DTM0102) = '8'">
<field name="DELIVERYDATE">
<xsl:value-of select="substring(DTM01/DTM0102, 7, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 5, 2)"/>-<xsl:value-of select="substring(DTM01/DTM0102, 1, 4)"/>
</field>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="GROUP_2" mode="YC1">
<xsl:choose>
<xsl:when test="NAD/NAD01 = 'SU'">
<xsl:if test="NAD/NAD03">
<field name="CAMPAIGNNUMBER">
<xsl:value-of select="NAD/NAD03"/>
</field>
</xsl:if> <xsl:apply-templates select="GROUP_3" mode="YC1"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="GROUP_3" mode="YC1">
<xsl:choose>
<xsl:when test="RFF/RFF01/RFF0101='YC1'">
<field name="CAMPAIGNNUMBER">
<xsl:value-of select="RFF/RFF01/RFF0102"/>
</field>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="GROUP_2" mode="NAD">
<xsl:choose>
<xsl:when test="NAD/NAD01='SU'">
<xsl:variable name="supplierRecordValue" select="NAD/NAD02/NAD0201"></xsl:variable>
<field name="SUPPLIER" recordUuid="{wdExtensions:getRecordUuidByValueFromDictionary('a5390637-f3b5-49f3-b7f6-48132f6fe8bb', '7f9d20ab-71d8-45e0-9756-2887fd427cd6', $supplierRecordValue)}">
<xsl:value-of select="$supplierRecordValue"/>
</field>
</xsl:when>
<xsl:when test="NAD/NAD01='BY'">
<xsl:variable name="buyer" select="string-length(NAD/NAD02/NAD0201)"/>
<xsl:choose>
<xsl:when test="$buyer=13">
<xsl:variable name="buyerRecordValue" select="NAD/NAD02/NAD0201"></xsl:variable>
<field name="BUYER" recordUuid="{wdExtensions:getRecordUuidByValueFromDictionary('258a20bd-ffe5-47b4-a76a-5d440469e444', '592553ba-3e02-43c1-bff6-b7fa438b8fda', $buyerRecordValue)}">
<xsl:value-of select="$buyerRecordValue"/>
</field>
</xsl:when>
<xsl:otherwise>
<field name="BUYERCODE">
<xsl:value-of select="NAD/NAD02/NAD0201"/>
</field>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="NAD/NAD01='DP'">
<xsl:variable name="deliveryPlaceValue" select="NAD/NAD02/NAD0201"></xsl:variable>
<field name="DELIVERYPLACE" recordUuid="{wdExtensions:getRecordUuidByValueFromDictionary('258a20bd-ffe5-47b4-a76a-5d440469e444', '592553ba-3e02-43c1-bff6-b7fa438b8fda', $deliveryPlaceValue)}">
<xsl:value-of select="$deliveryPlaceValue"/>
</field>
</xsl:when>
<xsl:when test="NAD/NAD01='IV'">
<xsl:variable name="invoicePartnerRecordValue" select="NAD/NAD02/NAD0201"></xsl:variable>
<field name="INVOICEPARTNER" recordUuid="{wdExtensions:getRecordUuidByValueFromDictionary('258a20bd-ffe5-47b4-a76a-5d440469e444', '592553ba-3e02-43c1-bff6-b7fa438b8fda', $invoicePartnerRecordValue)}">
<xsl:value-of select="$invoicePartnerRecordValue"/>
</field>
</xsl:when>
<xsl:when test="NAD/NAD01='CA'">
<xsl:if test="NAD/NAD02/NAD0201">
<xsl:if test="13>string-length(NAD/NAD02/NAD0201)">
<field name="RECIPIENTCODE">
<xsl:value-of select="NAD/NAD02/NAD0201"/>
</field>
</xsl:if>
</xsl:if>
<xsl:if test="NAD/NAD05">
<field name="RECIPIENTADRESS">
<xsl:value-of select="NAD/NAD05"/>
</field>
</xsl:if>
<xsl:if test="NAD/NAD06">
<field name="RECIPIENTCITY">
<xsl:value-of select="NAD/NAD06"/>
</field>
</xsl:if>
<xsl:if test="NAD/NAD04">
<field name="RECIPIENTNAME">
<xsl:value-of select="NAD/NAD04"/>
</field>
</xsl:if>
</xsl:when>
<xsl:when test="NAD/NAD01='CL'">
<field name="INVOICEPARTNER">
<xsl:value-of select="NAD/NAD02/NAD0201"/>
</field>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="GROUP_28">
<fieldset index="{position() - 1}">
<field name="POSITIONNUMBER">
<xsl:value-of select="position()"/>
</field>
<xsl:choose>
<xsl:when test="boolean(LIN/LIN03/LIN0301)">
<field name="PRODUCT">
<xsl:value-of select="LIN/LIN03/LIN0301"/>
</field>
</xsl:when>
<xsl:otherwise>
<field name="PRODUCT">4829090909095</field>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="PIA"/>
<xsl:apply-templates select="QTY"/>
<xsl:choose>
<xsl:when test="GROUP_32/PRI/PRI01/PRI0101 = 'AAA' and boolean(substring-before(GROUP_32/PRI/PRI01/PRI0102, '.'))">
<field name="ORDERPRICE">
<xsl:value-of select="substring-before(GROUP_32/PRI/PRI01/PRI0102, '.')"/>.<xsl:value-of select="substring(substring-after(GROUP_32/PRI/PRI01/PRI0102, '.'), 1, 3)"/>
</field>
</xsl:when>
<xsl:otherwise>
<xsl:if test="GROUP_32/PRI/PRI01/PRI0101 = 'AAA'">
<field name="ORDERPRICE">
<xsl:value-of select="GROUP_32/PRI/PRI01/PRI0102"/>
</field>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="IMD/IMD03/IMD0304">
<field name="CHARACTERISTIC_DESCRIPTION">
<xsl:value-of select="translate(IMD/IMD03/IMD0304, '&<>', '')"/><xsl:if test="boolean(IMD03/IMD0305)">(<xsl:value-of select="translate(IMD03/IMD0305, '&<>', '')"/>)</xsl:if>
</field>
</xsl:when>
</xsl:choose>
<xsl:if test="FTX"><xsl:apply-templates select="FTX"/></xsl:if>
</fieldset>
</xsl:template>
<xsl:template match="GROUP_28" mode="LOREAL">
<fieldset index="{position() - 1}">
<field name="POSITIONNUMBER">
<xsl:value-of select="position()"/>
</field>
<xsl:choose>
<xsl:when test="boolean(LIN/LIN03/LIN0301)">
<field name="PRODUCT">
<xsl:value-of select="LIN/LIN03/LIN0301"/>
</field>
</xsl:when>
<xsl:otherwise>
<field name="PRODUCT">4829090909095</field>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="PIA" mode="LOREAL"/>
<xsl:apply-templates select="QTY" mode="LOREAL"/>
</fieldset>
</xsl:template>
<xsl:template match="GROUP_25">
<fieldset index="{position() - 1}">
<field name="POSITIONNUMBER">
<xsl:value-of select="position()"/>
</field>
<xsl:choose>
<xsl:when test="boolean(LIN/LIN03/LIN0301)">
<field name="PRODUCT">
<xsl:value-of select="LIN/LIN03/LIN0301"/>
</field>
</xsl:when>
<xsl:otherwise>
<field name="PRODUCT">4829090909095</field>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates select="PIA"/>
<xsl:apply-templates select="QTY"/>
<xsl:choose>
<xsl:when test="GROUP_32/PRI/PRI01/PRI0101 = 'AAA' and boolean(substring-before(GROUP_32/PRI/PRI01/PRI0102, '.'))">
<field name="ORDERPRICE">
<xsl:value-of select="substring-before(GROUP_32/PRI/PRI01/PRI0102, '.')"/>.<xsl:value-of select="substring(substring-after(GROUP_32/PRI/PRI01/PRI0102, '.'), 1, 3)"/>
</field>
</xsl:when>
<xsl:when test="GROUP_28/PRI/PRI01/PRI0101 = 'AAA' and boolean(substring-before(GROUP_28/PRI/PRI01/PRI0102, '.'))">
<field name="ORDERPRICE">
<xsl:value-of select="substring-before(GROUP_28/PRI/PRI01/PRI0102, '.')"/>.<xsl:value-of select="substring(substring-after(GROUP_28/PRI/PRI01/PRI0102, '.'), 1, 3)"/>
</field>
</xsl:when>
<xsl:otherwise>
<xsl:if test="GROUP_32/PRI/PRI01/PRI0101 = 'AAA'">
<field name="ORDERPRICE">
<xsl:value-of select="GROUP_32/PRI/PRI01/PRI0102"/>
</field>
</xsl:if>
<xsl:if test="GROUP_28/PRI/PRI01/PRI0101 = 'AAA'">
<field name="ORDERPRICE">
<xsl:value-of select="GROUP_28/PRI/PRI01/PRI0102"/>
</field>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="IMD/IMD03/IMD0304">
<field name="CHARACTERISTIC_DESCRIPTION">
<xsl:value-of select="translate(IMD/IMD03/IMD0304, '&<>', '')"/><xsl:if test="boolean(IMD/IMD03/IMD0305)">(<xsl:value-of select="translate(IMD/IMD03/IMD0305, '&<>', '')"/>)</xsl:if>
</field>
</xsl:when>
</xsl:choose>
</fieldset>
</xsl:template>
<xsl:template match="PIA">
<xsl:choose>
<xsl:when test="PIA01 = '1'">
<xsl:if test="PIA02/PIA0202 = 'IN' or PIA02/PIA0202 = 'BP'">
<field name="PRODUCTIDBUYER">
<xsl:value-of select="PIA02/PIA0201"/>
</field>
</xsl:if>
<xsl:if test="PIA02/PIA0202 = 'SA'">
<field name="PRODUCTIDSUPPLIER">
<xsl:value-of select="PIA02/PIA0201"/>
</field>
</xsl:if>
</xsl:when>
<xsl:when test="PIA01 = '5'">
<xsl:if test="PIA02/PIA0202 = 'IN' or PIA02/PIA0202 = 'BP'">
<field name="BUYERPARTNUMBER">
<xsl:value-of select="PIA02/PIA0201"/>
</field>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="PIA" mode="LOREAL">
<xsl:choose>
<xsl:when test="PIA01 = '5'">
<xsl:if test="PIA02/PIA0202 = 'IN' or PIA02/PIA0202 = 'BP'">
<field name="PRODUCTIDBUYER">
<xsl:value-of select="PIA02/PIA0201"/>
</field>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="QTY">
<xsl:choose>
<xsl:when test="QTY01/QTY0101 = '21'">
<field name="ORDEREDQUANTITY">
<xsl:value-of select="QTY01/QTY0102"/>
</field>
<xsl:if test="boolean(QTY01/QTY0103)">
<field name="ORDERUNIT">
<xsl:variable name="orderUnitValue" select="QTY01/QTY0103"/>
<xsl:value-of select="wdExtensions:getValueFromDictionary('ee0aeb8e-ba06-41c7-8851-8ac38874fd4b', '52140044-da47-4cf9-90c6-988f44499d11', $orderUnitValue, '7aa2b0d9-bb42-4a4f-8588-46cfa4eda07c')"/>
</field>
</xsl:if>
</xsl:when>
<xsl:when test="QTY01/QTY0101 = '59'">
<field name="QUANTITYOFCUINTU">
<xsl:value-of select="QTY01/QTY0102"/>
</field>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="QTY" mode="LOREAL">
<xsl:choose>
<xsl:when test="QTY01/QTY0101 = '21'">
<field name="ORDEREDQUANTITY">
<xsl:value-of select="QTY01/QTY0102"/>
</field>
<xsl:if test="boolean(QTY01/QTY0103)">
<field name="ORDERUNIT">
<xsl:variable name="orderUnitValue" select="QTY01/QTY0103"/>
<xsl:value-of select="wdExtensions:getValueFromDictionary('ee0aeb8e-ba06-41c7-8851-8ac38874fd4b', '52140044-da47-4cf9-90c6-988f44499d11', $orderUnitValue, '7aa2b0d9-bb42-4a4f-8588-46cfa4eda07c')"/>
</field>
</xsl:if>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="FTX">
<xsl:choose>
<xsl:when test="FTX01='QQD'">
<field name="CONDITIONSTATUS">
<xsl:value-of select="FTX04"/>
</field>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template match="GROUP_2" mode="NADUP">
<xsl:if test="NAD/NAD01='DP'">
<xsl:choose>
<xsl:when test="NAD/NAD02/NAD0201 = 'xxxxxxxxxxxxx'">xxxxxxxxxxxxx</xsl:when>
<xsl:otherwise>9099999104043</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>
</xsl:stylesheet>