<!--
    
This file was generated by Altova MapForce 2009sp1

YOU SHOULD NOT MODIFY THIS FILE, BECAUSE IT WILL BE
OVERWRITTEN WHEN YOU RE-RUN CODE GENERATION.

Refer to the Altova MapForce Documentation for further details.
http://www.altova.com/mapforce
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n="http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:a="urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:i="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:clm54217="urn:un:unece:uncefact:codelist:specification:54217:2001" xmlns:clm5639="urn:un:unece:uncefact:codelist:specification:5639:1988" xmlns:clm66411="urn:un:unece:uncefact:codelist:specification:66411:2001" xmlns:clmIANAMIMEMediaType="urn:un:unece:uncefact:codelist:specification:IANAMIMEMediaType:2003" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" version="1.0" exclude-result-prefixes="a cac cbc clm54217 clm5639 clm66411 clmIANAMIMEMediaType ext i n qdt udt xs xsi xsl">
    <xsl:output method="xml" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <INVOIC_DIGITAL>
            <xsl:attribute name="xsi:noNamespaceSchemaLocation">
                <xsl:value-of select="'D:/Elektronički računi d.o.o/Holcim/LH XSD schema v22.xsd'"/>
            </xsl:attribute>
            <xsl:variable name="var1_instance" select="."/>
            <InvoiceType>
                <xsl:variable name="var2_map_select_OutgoingInvoicesData">
                    <xsl:if test="string(($var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference) = ($var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference)) != 'false'">
                        <xsl:value-of select="'1'"/>
                    </xsl:if>
                </xsl:variable>
                <xsl:choose>
                    <xsl:when test="string(boolean(string($var2_map_select_OutgoingInvoicesData))) != 'false'">
                        <xsl:value-of select="'MM'"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="'FI'"/>
                    </xsl:otherwise>
                </xsl:choose>
            </InvoiceType>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                <CustomerVAT>
                    <xsl:value-of select="concat('HR', string(n:OutgoingInvoice/n:BuyerID))"/>
                </CustomerVAT>
            </xsl:for-each>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                <VendorVAT>
                    <xsl:value-of select="concat('HR', string(n:Header/n:SupplierID))"/>
                </VendorVAT>
            </xsl:for-each>
            <Node>
                <xsl:value-of select="'1'"/>
            </Node>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                <InvoiceDate>
                    <xsl:value-of select="number(string(concat(concat(substring(string(n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cbc:IssueDate), 0, 5), substring(string(n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cbc:IssueDate), 6, 2)), substring(string(n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cbc:IssueDate), 9, 2))))"/>
                </InvoiceDate>
            </xsl:for-each>
            <CurrencyKey>
                <xsl:value-of select="'HRK'"/>
            </CurrencyKey>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:LegalMonetaryTotal/cbc:TaxExclusiveAmount">
                <NetAmount>
                    <xsl:value-of select="number(string(.))"/>
                </NetAmount>
            </xsl:for-each>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:TaxTotal">
                <TaxAmount>
                    <xsl:value-of select="number(string(cbc:TaxAmount))"/>
                </TaxAmount>
            </xsl:for-each>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                <GrossAmount>
                    <xsl:value-of select="number(string(n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:LegalMonetaryTotal/cbc:PayableAmount))"/>
                </GrossAmount>
            </xsl:for-each>
            <Text>
                <xsl:value-of select="''"/>
            </Text>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                <InvoiceNumber>
                    <xsl:value-of select="string(n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cbc:ID)"/>
                </InvoiceNumber>
            </xsl:for-each>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName">
                <VendorName>
                    <xsl:value-of select="string(.)"/>
                </VendorName>
            </xsl:for-each>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName">
                <CustomerName>
                    <xsl:value-of select="string(.)"/>
                </CustomerName>
            </xsl:for-each>
            <LINES>
                <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData">
                    <xsl:variable name="var21_OutgoingInvoicesData" select="."/>
                    <xsl:for-each select="n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:InvoiceLine">
                        <xsl:variable name="var23_InvoiceLine" select="."/>
                        <ART>
                            <LineNumber>
                                <xsl:value-of select="number(string(concat(string(cbc:ID), 0)))"/>
                            </LineNumber>
                            <TaxRate>
                                <xsl:value-of select="0"/>
                            </TaxRate>
                            <xsl:variable name="var37_">
                                <xsl:choose>
                                    <xsl:when test="$var23_InvoiceLine/cac:Item/cbc:Name">
                                        <xsl:variable name="var29_map_select_Name">
                                            <xsl:for-each select="cac:Item/cbc:Name">
                                                <xsl:value-of select="string(.)"/>
                                            </xsl:for-each>
                                        </xsl:variable>
                                        <xsl:variable name="var25_map_select_Name">
                                            <xsl:if test="string((string($var29_map_select_Name)) = (string($var29_map_select_Name))) != 'false'">
                                                <xsl:value-of select="'1'"/>
                                            </xsl:if>
                                        </xsl:variable>
                                        <xsl:if test="string(boolean(string($var25_map_select_Name))) != 'false'">
                                            <xsl:variable name="var26_map_select_Name">
                                                <xsl:for-each select="cac:Item/cbc:Name">
                                                    <xsl:value-of select="string(.)"/>
                                                </xsl:for-each>
                                            </xsl:variable>
                                            <xsl:value-of select="string($var26_map_select_Name)"/>
                                        </xsl:if>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:variable name="var32_map_select_Description">
                                            <xsl:for-each select="cac:Item/cbc:Description">
                                                <xsl:value-of select="'1'"/>
                                            </xsl:for-each>
                                        </xsl:variable>
                                        <xsl:if test="string(boolean(string($var32_map_select_Description))) != 'false'">
                                            <xsl:for-each select="cac:Item/cbc:Description">
                                                <xsl:value-of select="string(.)"/>
                                            </xsl:for-each>
                                        </xsl:if>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                            <ItemDescription>
                                <xsl:copy-of select="$var37_"/>
                            </ItemDescription>
                            <xsl:for-each select="cbc:InvoicedQuantity">
                                <Quantity>
                                    <xsl:value-of select="number(string(.))"/>
                                </Quantity>
                            </xsl:for-each>
                            <UnitOfMeasure>
                            <xsl:choose>
                                <xsl:when test="normalize-space(cac:Price/cbc:BaseQuantity/@unitCode) != '' " >
                                        <xsl:value-of select="cac:Price/cbc:BaseQuantity/@unitCode"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="cbc:InvoicedQuantity/@unitCode"/>
                                </xsl:otherwise>
                            </xsl:choose>   
                            </UnitOfMeasure>
                            <xsl:variable name="var46_select_OrderReference">
                                <xsl:if test="string(($var21_OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference) = ($var21_OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference)) != 'false'">
                                    <xsl:value-of select="'1'"/>
                                </xsl:if>
                            </xsl:variable>
                            <xsl:variable name="var41_cond_result_exists">
                                <xsl:choose>
                                    <xsl:when test="string(boolean(string($var46_select_OrderReference))) != 'false'">
                                        <xsl:variable name="var47_map_select_OrderReference">
                                            <xsl:for-each select="$var21_OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference">
                                                <xsl:value-of select="string(cbc:ID)"/>
                                            </xsl:for-each>
                                        </xsl:variable>
                                        <xsl:if test="string((string($var47_map_select_OrderReference)) = (string($var47_map_select_OrderReference))) != 'false'">
                                            <xsl:value-of select="'1'"/>
                                        </xsl:if>
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="'1'"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                            <xsl:if test="string(boolean(string($var41_cond_result_exists))) != 'false'">
                                <PurchaseOrder>
                                    <xsl:variable name="var42_cond_result_exists">
                                        <xsl:choose>
                                            <xsl:when test="$var21_OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference">
                                                <xsl:variable name="var43_map_select_OrderReference">
                                                    <xsl:for-each select="$var21_OutgoingInvoicesData/n:OutgoingInvoice/n:InvoiceEnvelope/i:Invoice/cac:OrderReference">
                                                        <xsl:value-of select="string(cbc:ID)"/>
                                                    </xsl:for-each>
                                                </xsl:variable>
                                                <xsl:value-of select="string($var43_map_select_OrderReference)"/>
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:value-of select="''"/>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:variable>
                                    <xsl:value-of select="number(string(string($var42_cond_result_exists)))"/>
                                </PurchaseOrder>
                            </xsl:if>
                            <DeliveryNote>
                                <xsl:value-of select="0"/>
                            </DeliveryNote>
                            <LineNetAmount>
                                <xsl:value-of select="number(string(cbc:LineExtensionAmount))"/>
                            </LineNetAmount>
                        </ART>
                    </xsl:for-each>
                </xsl:for-each>
            </LINES>
            <xsl:for-each select="$var1_instance/n:OutgoingInvoicesData/n:OutgoingInvoice/n:AttachedDocumentEnvelope/a:AttachedDocument/cac:Attachment/cbc:EmbeddedDocumentBinaryObject">
                <EmbeddedFilename>
                    <xsl:value-of select="string(.)"/>
                </EmbeddedFilename>
            </xsl:for-each>
        </INVOIC_DIGITAL>
    </xsl:template>
</xsl:stylesheet>