Приклад правила перетворення для вхідних документів

Написано Анатолій
Оновлено 5 місяців тому
<?xml version="1.0" encoding="ISO-8859-5"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:uuid="java:java.util.UUID"
                xmlns:saxon="http://saxon.sf.net/"
                xmlns:wdExtensions="java:com.whitedoc.xslt.extensions.WdExtensions"
                exclude-result-prefixes="saxon wdExtensions">
    <xsl:output indent="yes" omit-xml-declaration="yes" encoding="ISO-8859-5" method="text"/>
    <xsl:variable name="uid" select="uuid:randomUUID()"/>
    <xsl:param name="senderMailboxUuid" select="envelope/flow/roles/role[1]/@mailboxUuid"/>
    <xsl:param name="recipientMailboxUuid" select="envelope/flow/roles/role[2]/@mailboxUuid"/>
    <xsl:variable name="senderGLN" select="wdExtensions:getValueFromDictionary('5bc5be5a-751d-4ae3-8ad8-3a6ac1ab71c8', '1ddf9e46-49f5-41a2-b6f5-7c3015bc4505', $senderMailboxUuid, '4f68fbf0-d78d-4aef-9192-bccd0c8d6011')"/>
    <xsl:variable name="recipientGLN" select="wdExtensions:getValueFromDictionary('5bc5be5a-751d-4ae3-8ad8-3a6ac1ab71c8', '1ddf9e46-49f5-41a2-b6f5-7c3015bc4505', $recipientMailboxUuid, '4f68fbf0-d78d-4aef-9192-bccd0c8d6011')"/>
    <xsl:template match="/">
        <xsl:apply-templates select="envelope/documents/document"/>
    </xsl:template>
    <xsl:template match="document">
        <xsl:choose>
            <xsl:when test="$recipientGLN='4820086639637'">
                <xsl:call-template name="DESADV"/>
            </xsl:when>
            <xsl:when test="$recipientGLN='4820086630009'">
                <xsl:call-template name="DESADV"/>
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    <xsl:template name="DESADV">
        <xsl:param name="date" select="field[@name='DATE']"/>
        <xsl:param name="Orderdate" select="field[@name='ORDERDATE']"/>
        <xsl:choose>
            <xsl:when test="$senderGLN=('4820110633693','4820110633785','9863521000093','9863521003131','9863521004022','9863521004015','9863521008150')">Lasynia wrong</xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="$senderGLN='4824025030288'">UNB+UNOC:3+4829900005924</xsl:when>
                    <xsl:when test="$senderGLN='9863521027830'">UNB+UNOC:3+4829900006907</xsl:when>
                    <xsl:when test="$senderGLN='9863521030045'">UNB+UNOC:3+4829900006891</xsl:when>
                    <xsl:when test="$senderGLN='4820110631736'">UNB+UNOC:3+9863571155385</xsl:when>
                    <xsl:when test="$senderGLN='9864082514562'">UNB+UNOC:3+4829900015633</xsl:when>
                    <xsl:otherwise>UNA:+.? '
                    UNB+UNOE:3+<xsl:value-of select="$senderGLN"/></xsl:otherwise>
                        </xsl:choose>:14+<xsl:value-of select="$recipientGLN"/>:14+<xsl:value-of select="translate(substring($date, 3, 8), '-', '')"/>:0000+<xsl:value-of select="substring(translate($uid,'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-',''),1,14)"/><xsl:call-template name="TESTFLAGREAL"/>'
                        UNH+<xsl:value-of select="substring(translate(field[@name='NUMBER'], '№ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-#!@$%^*№()-_=+:;', ''),1,14)"/>+DESADV:D:01B:UN:EAN007'
                        BGM+351+<xsl:value-of select="field[@name='NUMBER']"/>+9'
                        DTM+137:<xsl:value-of select="translate($date, '-', '')"/>:102'<xsl:choose><xsl:when test="$recipientGLN='4820086639637'">
                        DTM+17:<xsl:value-of select="translate(field[@name='DELIVERYDATE'], '-', '')"/><xsl:value-of select="translate(field[@name='DELIVERYTIME'], ':', '')"/>:203'</xsl:when><xsl:otherwise>
                        DTM+17:<xsl:value-of select="translate(field[@name='DELIVERYDATE'], '-', '')"/>:102'</xsl:otherwise></xsl:choose><xsl:if test="field[@name='ORDERNUMBER']">
                        RFF+ON:<xsl:value-of select="substring(field[@name='ORDERNUMBER'], 1, 15)"/>'</xsl:if>
                        DTM+171:<xsl:value-of select="translate($Orderdate, '-', '')"/>:102'<xsl:if test="boolean(field[@name='DELIVERYNOTENUMBER'])">
                        RFF+DQ:<xsl:value-of select="substring(field[@name='DELIVERYNOTENUMBER'], 1, 15)"/>'</xsl:if>
                        NAD+BY+<xsl:value-of select="normalize-space(field[@name='BUYER'])"/>::9'
                        NAD+SU+<xsl:value-of select="normalize-space(field[@name='SUPPLIER'])"/>::9'<xsl:if test="field[@name='CAMPAIGNNUMBER']">
                        RFF+YC1:<xsl:value-of select="field[@name='CAMPAIGNNUMBER']"/>'</xsl:if>
                        NAD+DP+<xsl:value-of select="normalize-space(field[@name='DELIVERYPLACE'])"/>::9'
                        CPS+1'<xsl:if test="field[@name='TOTALPALLETS']">
                        PAC+<xsl:value-of select="field[@name='TOTALPALLETS']"/>++201::9'</xsl:if><xsl:if test="field[@name='TOTALPACKAGES']">
                        PAC+<xsl:value-of select="field[@name='TOTALPACKAGES']"/>++PK'</xsl:if><xsl:apply-templates select="fieldgroup[@name='PACKINGSEQUENCE']/fieldset" mode="ALL"/></xsl:otherwise>
        </xsl:choose>
        <xsl:choose>
            <xsl:when test="field/@name='BUYER' and field='4824025000007'">UNT+<xsl:call-template name="KONTRCIFRABILLA"/>+<xsl:value-of select="substring(translate(field[@name='NUMBER'], '№ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-#!@$%^*()-_=+:;', ''), 1, 14)"/>'UNZ+1+<xsl:value-of select="substring(translate($uid,'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-',''),1,14)"/>'</xsl:when>
            <xsl:when test="$senderGLN='4829900002626'">
                <xsl:if test="field[@name='TOTALPACKAGES']">CNT+11:<xsl:value-of select="field[@name='TOTALPACKAGES']"/>'</xsl:if>UNT+<xsl:call-template name="KONTRCIFRA_MTI"/>+<xsl:value-of select="substring(translate(field[@name='NUMBER'], '№ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-#!@$%^*()-_=+:;', ''),1,14)"/>'
                UNZ+1+<xsl:value-of select="substring(translate($uid,'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-',''),1,14)"/>'</xsl:when>
            <xsl:otherwise>
            UNT+<xsl:if test="boolean(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='ORDEREDQUANTITY'])"><xsl:call-template name="KONTRCIFRA"/></xsl:if><xsl:if test="not(boolean(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='ORDEREDQUANTITY']))"><xsl:call-template name="KONTRCIFRA_BEZ_ORDEREDQUANTITY"/></xsl:if>+<xsl:value-of select="substring(translate(field[@name='NUMBER'], '№ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-#!@$%^*()-_=+:;', ''),1,14)"/>'
            UNZ+1+<xsl:value-of select="substring(translate($uid,'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-',''),1,14)"/>'</xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="fieldgroup[@name='PACKINGSEQUENCE']/fieldset" mode="BILLA">LIN+<xsl:value-of select="position()"/>++<xsl:value-of select="translate(field[@name='PRODUCT'], ' ','')"/>:SRV'<xsl:if test="boolean(field[@name='PRODUCTIDBUYER'])">PIA+1+<xsl:value-of select="field[@name='PRODUCTIDBUYER']"/>:IN::92'</xsl:if><xsl:if test="boolean(field[@name='PRODUCTIDSUPPLIER'])">PIA+1+<xsl:value-of select="field[@name='PRODUCTIDSUPPLIER']"/>:SU::92'</xsl:if>QTY+12:<xsl:value-of select="field[@name='DELIVEREDQUANTITY']"/><xsl:if test="field/@name='DELIVEREDUNIT' and field='KGM'">:KGM</xsl:if>'<xsl:if test="boolean(field[@name='ORDEREDQUANTITY'])">QTY+21:<xsl:value-of select="field[@name='ORDEREDQUANTITY']"/>'</xsl:if></xsl:template>

    <xsl:template match="fieldgroup[@name='PACKINGSEQUENCE']/fieldset" mode="ALL">
    LIN+<xsl:value-of select="position()"/>++<xsl:value-of select="translate(field[@name='PRODUCT'], ' ','')"/>:SRV'<xsl:if test="boolean(field[@name='PRODUCTIDBUYER'])">
    PIA+1+<xsl:value-of select="field[@name='PRODUCTIDBUYER']"/>:IN::92'</xsl:if><xsl:if test="field[@name='PACKAGEID']">
    PIA+1+<xsl:value-of select="field[@name='PACKAGEID']"/>:CG::92'</xsl:if><xsl:choose><xsl:when test="field[@name='DELIVERYQUANTITY']">
    QTY+12:<xsl:value-of select="field[@name='DELIVERYQUANTITY']"/><xsl:if test="field/@name='DELIVEREDUNIT' and field='KGM'">:KGM</xsl:if>'</xsl:when><xsl:otherwise>
    QTY+12:<xsl:value-of select="field[@name='DELIVEREDQUANTITY']"/><xsl:if test="field/@name='DELIVEREDUNIT' and field='KGM'">:KGM</xsl:if>'</xsl:otherwise></xsl:choose><xsl:choose><xsl:when test="string-length(field[@name='ORDEREDQUANTITY'])!=0">
    QTY+21:<xsl:value-of select="field[@name='ORDEREDQUANTITY']"/>'</xsl:when><xsl:otherwise>
    QTY+21:<xsl:value-of select="field[@name='DELIVEREDQUANTITY']"/>'</xsl:otherwise></xsl:choose><!--<xsl:if test="DESCRIPTION">
    FTX+DEL+1+002+<xsl:value-of select="DESCRIPTION"/>'</xsl:if>--><xsl:if test="field[@name='CONDITIONSTATUS']">
    FTX+QQD+1+002+<xsl:value-of select="field[@name='CONDITIONSTATUS']"/>'</xsl:if></xsl:template>


    <xsl:template name="KONTRCIFRA">

        <xsl:value-of select="10 + count(field[@name='CAMPAIGNNUMBER']) + count(field[@name='TOTALPACKAGES']) + count(field[@name='TOTALPALLETS']) +  count(field[@name='DELIVERYNOTENUMBER']) +   count(field[@name='DELIVERYPLACE']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCT']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCTIDBUYER']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DELIVEREDQUANTITY']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='ORDEREDQUANTITY'])  "/>
    </xsl:template>

    <xsl:template name="KONTRCIFRA_BEZ_ORDEREDQUANTITY">
        <xsl:value-of select="10 +    count(field[@name='DELIVERYNOTENUMBER']) +   count(field[@name='DELIVERYPLACE']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCT']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCTIDBUYER']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DELIVEREDQUANTITY']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DELIVEREDQUANTITY'])   "/>
    </xsl:template>

    <xsl:template name="KONTRCIFRABILLA">

        <xsl:value-of select="11 +    count(field[@name='DELIVERYNOTENUMBER']) +   count(field[@name='DELIVERYPLACE']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCT']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCTIDBUYER']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DELIVEREDQUANTITY']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='ORDEREDQUANTITY'])  "/>
    </xsl:template>

    <xsl:template name="KONTRCIFRA_MTI">

        <xsl:value-of select="3 +   count(field[@name='NUMBER']) +   count(field[@name='DATE']) +   count(field[@name='DELIVERYDATE']) +   count(field[@name='ORDERNUMBER']) +   count(field[@name='ORDERDATE']) +   count(field[@name='DELIVERYNOTENUMBER']) +   count(field[@name='BUYER']) +   count(field[@name='BUYERCODE']) +   count(field[@name='SUPPLIER']) +   count(field[@name='DELIVERYPLACE']) +   count($senderGLN) +   count(field[@name='SENDERNAME']) +   count(field[@name='SENDERPHONE']) +   count(field[@name='INFO']) +   count(field[@name='TRANSPORTID']) +    count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCT']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCTIDBUYER']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PRODUCTIDSUPPLIER']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DELIVEREDQUANTITY']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='ORDEREDQUANTITY']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='DESCRIPTION']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='CONDITIONSTATUS']) +   count(fieldgroup[@name='PACKINGSEQUENCE']/fieldset/field[@name='PACKAGEID'])+    count(field[@name='TOTALPACKAGES'])   "/>
    </xsl:template>

    <xsl:template name="DATEPLUS1">
        <xsl:variable name="Date" select="field[@name='DATE']"/>
        <xsl:variable name="Plus" select="translate($Date, '-', '')"/>
        <xsl:choose>
            <xsl:when test="substring($Plus,5,4) = 0228">20100301</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0331">20100401</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0430">20100501</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0531">20100601</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0630">20100701</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0731">20100801</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0831">20100901</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 0930">20101001</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 1031">20101101</xsl:when>
            <xsl:when test="substring($Plus,5,4) = 1130">20101201</xsl:when>
            <xsl:when test="$Plus = 20091231">20100101</xsl:when>
            <xsl:when test="$Plus = 20101231">20110101</xsl:when>
            <xsl:otherwise>
                <xsl:variable name="Char" select="$Plus+1"/>
                <xsl:variable name="Transform" select="translate($Char,'.', '')"/>
                <xsl:value-of select="substring($Transform,1,8)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="NUMB1">
        <xsl:variable name="literals">+?"'&amp;&lt;&gt;</xsl:variable>
        <xsl:value-of select="substring(translate(field[@name='NUMBER'], 'ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-№#!@$%^*№()-_=+:;', ''), $literals, '')"/>
    </xsl:template>

    <xsl:template name="NUMB">
        <xsl:value-of select="translate(field[@name='NUMBER'], 'ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-№#!@$%^*№()-_=+:;', '')"/>
    </xsl:template>

    <xsl:template name="DELIVERYNOTENUMBER">
        <xsl:value-of select="translate(field[@name='DELIVERYNOTENUMBER'], 'ІіЙйЦцУуКкЕеНнГгШшЩщЗзХхЪъЭэЖжДдЛлОоРрПпАаВвЫыФфЯяЧчСсМмИиТтЬьБбЮюЁёЇїЄє AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz-№#!@$%^*№()-_=+:;', '')"/>
    </xsl:template>

    <xsl:template name="TESTFLAGREAL">
        <xsl:choose>
            <xsl:when test="$recipientGLN='4820086630009'"></xsl:when>
            <xsl:when test="$recipientGLN='4820086639637'"></xsl:when>
            <xsl:otherwise>++++++1</xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
Чи була наша стаття корисною?