<?xml version="1.0" encoding="UTF-8"?>
<!-- ===== Copyright Notice ===== -->
<!--  
 Copyright (C) Elektronički Računi d.o.o 2019. All Rights Reserved.

Elektronički Računi d.o.o  takes no position regarding the validity or scope of any 
  intellectual property or other rights that might be claimed to pertain 
  to the implementation or use of the technology described in this 
  document or the extent to which any license under such rights 
  might or might not be available; neither does it represent that it has 
  made any effort to identify any such rights. 

This document and translations of it may be copied and furnished to 
  others, in whole or in part, for the purpose of integration with
  Moj eRačun network, provided that the above copyright notice and this 
  paragraph are included on all such copies and derivative works. 
  Other usages of the document or its translations are prohibited.
  However, this document itself may not be modified in any way, 
  such as by removing the copyright notice or references to 
  OASIS 
-->

<!-- V2019-12-04-v12
*** AllowanceCharge na razini dokumenta generira se samo ako  TaxTotalu postoji stopa poreza ili ako je Amount > 0

-->

<!-- V 2019-11-30-v11
*** Ignorira ID porezne kategorije ako je E ili S (generira prema vrijednosti postotka)


-->
<!-- V2019-11-27-v10
*** AllowanceCharge na Invoice razini kreira TaxCategory

*** Ispravljene greške sa formatom ako je 0 i PDV stopom na AllowanceChage na Invoice razini

-->
<!-- V2019-11-18-v8
*** Dodaje InvoiceIssuer i za CROSCO i Croplin

*** Generira porezne kategorije ako nisu popunjene

-->
<!-- V2019-11-11-v07
*** Dodaje različite InvoiceIssuer ovisno o OIB-u za INU, Maziva i STSI

*** Mijenja PaymentID i InstructionID

-->
<!-- V2019-11-06-v6
*** CopyIndicator - translate to lowercase

*** AdditionalDocumentReference/DocumentTypeCode removed

*** MultiplierFactorNumeric - postavlja 0 kao standardnu vrijednost ako je prazan

*** TaxSubtotal - ako nedostaje čvor TaxCategory, postavlja 25% kategorija S

-->
<!-- V 2019-10-21-V5
*** Maknuti namespace prefixi iz xml deklaracije za header i invoice elemente
-->

 <!-- V 2019-10-14-v4
*** Stavljen adresarv@moj-eracun.hr u Recipient/ElectronicMail i 

*** Stavljen default namespace u AttachedDocument

*** Maknut Receipt čvor (kompletno)

*** Terećenje varaćeno u OutgoingInvoicesData header - struktura ista kao račun

*** PaymentMeansCode fiksiran na 42
-->


<xsl:stylesheet version="1.0" 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:xades="http://uri.etsi.org/01903/v1.3.2#" 
 xmlns:n2="http://uri.etsi.org/01903/v1.4.1#" 
 xmlns:ds="http://www.w3.org/2000/09/xmldsig#" 
 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 xmlns:ns0="http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2" 
 xmlns:ns1="urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2" 
 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:n0="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" 
 xmlns:i="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" 
 xmlns:qdt2="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2" 
 xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" 
 xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" 
 xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2" 
 xmlns:udt2="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-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:ccts-cct="urn:un:unece:uncefact:data:specification:CoreComponentTypeSchemaModule:2" 
 xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" 
 xmlns:ihi="urn:invoice:hr:issueplace"
 xmlns:iht="urn:invoice:hr:saptypeID"
 exclude-result-prefixes="ccts-cct ds n0 n2 qdt2 sac sbc udt2 xades xs xsi xsl ihi n i a ns1 iht" 
 xmlns="http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2">
	
	<xsl:namespace-alias stylesheet-prefix="n" result-prefix="#default"/>
	<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
	<xsl:variable name="SAPTypeID">
		<xsl:choose>
			<xsl:when test="(//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '15538072333' or //cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '99172175603') and //cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '27759560625'">
				<xsl:value-of select="//iht:SAPTypeID"/>
			</xsl:when>
			<xsl:otherwise></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<xsl:variable name="_defStandardnaStopaPDV">25</xsl:variable>
	
	<xsl:variable name="issueTime">
		<xsl:value-of select="/i:Invoice/cbc:IssueTime" />
	</xsl:variable>
	
	<xsl:variable name="supplierCompanyId">
		<xsl:value-of select="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID" />
	</xsl:variable>
	
	<xsl:variable name="supplierRegistrationName">
		<xsl:choose>
			<xsl:when test="//cac:AccountingSupplierParty//cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(//cac:AccountingSupplierParty//cac:PartyLegalEntity/cbc:RegistrationName) != '')">
				<xsl:value-of select="normalize-space(//cac:AccountingSupplierParty//cac:PartyLegalEntity/cbc:RegistrationName)" />
			</xsl:when>
			<xsl:when test="//cac:AccountingSupplierParty//cac:PartyName/cbc:Name and (normalize-space(//cac:AccountingSupplierParty//cac:PartyName/cbc:Name) != '')">
				<xsl:value-of select="normalize-space(//cac:AccountingSupplierParty//cac:PartyName/cbc:Name)" />
			</xsl:when>
		
		</xsl:choose>
	
	
	</xsl:variable>
	
	<xsl:variable name="customerCompanyId">
		<xsl:value-of select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID" />
	</xsl:variable>


	<xsl:variable name="customerRegistrationName">
		<xsl:choose>
			<xsl:when test="//cac:AccountingCustomerParty//cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(//cac:AccountingCustomerParty//cac:PartyLegalEntity/cbc:RegistrationName) != '')">
				<xsl:value-of select="normalize-space(//cac:AccountingCustomerParty//cac:PartyLegalEntity/cbc:RegistrationName)" />
			</xsl:when>
			<xsl:when test="//cac:AccountingCustomerParty//cac:PartyName/cbc:Name and (normalize-space(//cac:AccountingCustomerParty//cac:PartyName/cbc:Name) != '')">
				<xsl:value-of select="normalize-space(//cac:AccountingCustomerParty//cac:PartyName/cbc:Name)" />
			</xsl:when>
		
		</xsl:choose>
	</xsl:variable>
	
	
	<xsl:variable name="invoiceID">
		<xsl:value-of select="/i:Invoice/cbc:ID" />
	</xsl:variable>
	


	
	<xsl:template match="/">
<!--		<xsl:comment>
			Generated by Moj eRačun INA-2-HRInvoice transformation V2019-10-14-v3
		</xsl:comment>-->
		<xsl:choose>
			<xsl:when test="/i:Invoice/cbc:InvoiceTypeCode/text() = 381"><xsl:call-template name="CreditNoteEnvelope" /></xsl:when>
			<!--<xsl:when test="/i:Invoice/cbc:InvoiceTypeCode/text() = 383"><xsl:call-template name="DebitNoteEnvelope" /></xsl:when>-->
			<xsl:otherwise><xsl:call-template name="OutgoingInvoicesData" /></xsl:otherwise>
		</xsl:choose>

	</xsl:template>
	
	<xsl:template name="CreditNoteEnvelope">
		<OutgoingDocumentsData xmlns="http://ubl.moj-eracun.hr/v1.2/xsd">

			<xsl:call-template name="HROutgoingDocumentsHeader" />
			<CdnDocument>
				
				<CreditNoteEnvelope>
					<xsl:apply-templates select="/i:Invoice" />
				</CreditNoteEnvelope>
				<AttachedDocumentEnvelope>
					<!--<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[(cbc:Name/text() = 'PDF') or (position() = last())]" mode="Attachment" />-->
					<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[not(position()=1)]" mode="Attachment" />

				</AttachedDocumentEnvelope>
			</CdnDocument>
		</OutgoingDocumentsData>
	
	</xsl:template>
	
	<xsl:template name="DebitNoteEnvelope">
		<OutgoingDocumentsData xmlns="http://ubl.moj-eracun.hr/v1.2/xsd">

			<xsl:call-template name="HROutgoingDocumentsHeader" />
			<CdnDocument>
				
				<DebitNoteEnvelope>
					<xsl:apply-templates select="/i:Invoice" />
				</DebitNoteEnvelope>
				<AttachedDocumentEnvelope>
					<!--<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[(cbc:Name/text() = 'PDF') or (position() = last())]" mode="Attachment" />-->
					<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[not(position()=1)]" mode="Attachment" />

				</AttachedDocumentEnvelope>
			</CdnDocument>
		</OutgoingDocumentsData>
	
	</xsl:template>

	<xsl:template name="HROutgoingDocumentsHeader" >
		<Header xmlns="http://ubl.moj-eracun.hr/v1.2/xsd">
			<Sender>
				<cbc:CompanyID>
					<xsl:value-of select="string(/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID)"/>
				</cbc:CompanyID>
				<cbc:ElectronicMail>
					<xsl:value-of select="string(/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:Contact/cbc:ElectronicMail)"/>
				</cbc:ElectronicMail>
			</Sender>
			<Recipient>
				<cbc:CompanyID>
					<xsl:value-of select="string(/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID)"/>
				</cbc:CompanyID>
				<xsl:if test="/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID and normalize-space(/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID) != ''">
					<cac:PartyIdentification>
						<cbc:ID><xsl:value-of select="/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID"/></cbc:ID>
					</cac:PartyIdentification>
				</xsl:if>
				<cbc:ElectronicMail>adresar@moj-eracun.hr</cbc:ElectronicMail>
			</Recipient>
			<DocumentWorkflow>
				<DocumentType>381</DocumentType>
				<SignDocument>2</SignDocument>
				
					<xsl:apply-templates select="/i:Invoice/cbc:ID" mode="HeaderFiscalNumber" />
				
				<ResponseRequired>true</ResponseRequired>
			</DocumentWorkflow>

		</Header>
<!--	<Receipt xmlns="http://ubl.moj-eracun.hr/v1.2/xsd">
			<ElectronicID>
				<xsl:value-of select="string(/i:Invoice/cbc:ID)"/>
			</ElectronicID>		
		</Receipt>-->
	</xsl:template>

	
	<xsl:template name="OutgoingInvoicesData">
		<OutgoingInvoicesData xmlns="http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2">
			<xsl:attribute name="xsi:schemaLocation">http://fina.hr/eracun/erp/OutgoingInvoicesData/v3.2 D:/Downloads/examples-schemes-namespaces/xsd/OutgoingInvoicesData.xsd urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 file:///D:/E-poslovanje/UBL2.1/xsd/maindoc/UBL-Invoice-2.1.xsd</xsl:attribute>

			
			<xsl:call-template name="HRInvoiceHeader" />
			<OutgoingInvoice>
				<xsl:call-template name="HROutgoingInvoiceHeader" />
				<InvoiceEnvelope>
					<xsl:apply-templates select="/i:Invoice" />
				</InvoiceEnvelope>
				<AttachedDocumentEnvelope>
					<!--<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[cbc:Name/text() = 'PDF']" mode="Attachment" />-->
					<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions/ext:UBLExtension[not(position()=1)]" mode="Attachment" />
				</AttachedDocumentEnvelope>
			</OutgoingInvoice>
		</OutgoingInvoicesData>
	
	</xsl:template>
	
	<xsl:template match="ext:UBLExtension" mode="Attachment">
		<AttachedDocument xmlns="urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2">
			<cbc:ID>
				<xsl:value-of select="concat($invoiceID, ':Vizualizacija')" />
			</cbc:ID>
			<cbc:IssueDate>
				<xsl:value-of select="/i:Invoice/cbc:IssueDate"/>
			</cbc:IssueDate>
			<cbc:IssueTime>
				<xsl:value-of select="$issueTime" />
			</cbc:IssueTime>
			<cbc:DocumentType>
				<xsl:value-of select="cbc:DocumentType"/>
			</cbc:DocumentType>
			<cbc:ParentDocumentID><xsl:value-of  select="/i:Invoice/cbc:ID" /></cbc:ParentDocumentID>
			<cac:SenderParty>
				<xsl:apply-templates select="/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity" mode="SupplierAttachment" />
			</cac:SenderParty>
			<cac:ReceiverParty>
				<xsl:apply-templates select="/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity" mode="CustomerAttachment" />
			</cac:ReceiverParty>
			
			<xsl:apply-templates select="ext:ExtensionContent" mode="Attachment" />

		</AttachedDocument>
	</xsl:template>
	
	<xsl:template match="cac:PartyLegalEntity" mode="SupplierAttachment" >
		<cac:PartyLegalEntity>
			<cbc:RegistrationName>
				<xsl:value-of select="cbc:RegistrationName"/>
			</cbc:RegistrationName>
			<cbc:CompanyID>
				<!--<xsl:value-of select="cbc:CompanyID" />-->
				<xsl:value-of select="$supplierCompanyId" />
			</cbc:CompanyID>
					
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template match="cac:PartyLegalEntity" mode="CustomerAttachment" >
		<cac:PartyLegalEntity>
			<cbc:RegistrationName>
				<xsl:value-of select="cbc:RegistrationName"/>
			</cbc:RegistrationName>
			<cbc:CompanyID>
				<!--<xsl:value-of select="cbc:CompanyID" />-->
				<xsl:value-of select="$customerCompanyId" />
			</cbc:CompanyID>
					
		</cac:PartyLegalEntity>
	
	</xsl:template>


	<xsl:template match="ext:ExtensionContent" mode="Attachment" >
		<cac:Attachment>
			<xsl:choose>
				<xsl:when test="cbc:EmbeddedDocumentBinaryObject"><xsl:apply-templates select="cbc:EmbeddedDocumentBinaryObject" /></xsl:when>
				<xsl:when test="normalize-space(text()) != ''"><xsl:call-template name="EmbeddedDocumentBinaryObject" /></xsl:when>
			</xsl:choose>
		
		
		</cac:Attachment>
	
	</xsl:template>
	
		
	<xsl:template match="cbc:EmbeddedDocumentBinaryObject" name="EmbeddedDocumentBinaryObject">
		<cbc:EmbeddedDocumentBinaryObject>
			<xsl:attribute name="mimeCode" namespace="">application/pdf</xsl:attribute>
		
			<xsl:attribute name="filename" namespace="">
				<xsl:value-of select="concat(translate($invoiceID, ':/\&amp;', '--_ '), '.PDF')"/>
			</xsl:attribute>

			<xsl:value-of select="."/>
			
		</cbc:EmbeddedDocumentBinaryObject>
	
	</xsl:template>
	
	
	<xsl:template match="i:Invoice">
		<xsl:copy>
				
			<ext:UBLExtensions>
					<ext:UBLExtension>
						<cbc:ID>HRINVOICE1</cbc:ID>
						<cbc:Name>InvoiceIssuerData</cbc:Name>
						<ext:ExtensionAgencyID>FINA</ext:ExtensionAgencyID>
						<ext:ExtensionAgencyName>FINA</ext:ExtensionAgencyName>
						<ext:ExtensionAgencyURI>FINA</ext:ExtensionAgencyURI>
						<ext:ExtensionURI>urn:invoice:hr:issuer</ext:ExtensionURI>
						<ext:ExtensionReasonCode>MandatoryField</ext:ExtensionReasonCode>
						<ext:ExtensionReason>Podaci o izdavatelju prema Zakonu o trgovačkim društvima</ext:ExtensionReason>
						<ext:ExtensionContent>
							<ext:InvoiceIssuer>
							<xsl:choose>
								<xsl:when test="normalize-space($supplierCompanyId) = '63988426425'">
INA MAZIVA d.o.o.| Radnička cesta 175 | p.p. 270 | 10 000 Zagreb | Hrvatska | Trgovački sud u Zagrebu | MBS: 080422876| OIB - 63988426425 | Uplaćen temeljni kapital | 150.213.100,00 kn - HRK								
								</xsl:when>
								<xsl:when test="normalize-space($supplierCompanyId) = '99172175603'">
STSI - Integrirani tehnički servisi d.o.o.| Lovinčićeva 4 | p.p. 758 | 10 002 Zagreb | Hrvatska | Trgovački sud u Zagrebu | MBS: 1600915 | OIB - 99172175603| Uplaćen temeljni kapital | 140.227.800,00 kn - HRK							
								</xsl:when>
								<xsl:when test="normalize-space($supplierCompanyId) = '35570445777'">
Croplin d.o.o.| Avenija Veceslava Holjevca 10 | 10 000 Zagreb | Hrvatska | Trgovački sud u Zagrebu | MBS: 080251104| OIB - 35570445777| Uplaćen temeljni kapital  : 37.579,00 kn - HRK | IBAN: HR1824840081102573223 | Direktor društva : Damir Škugor						
								</xsl:when>
								<xsl:when test="normalize-space($supplierCompanyId) = '15538072333'">
CROSCO d.o.o.| Ulica grada Vukovara 18 | 10 000 Zagreb | Hrvatska | Trgovački sud u Zagrebu | MBS: 080114508| OIB - 15538072333| Uplaćen temeljni kapital | 945.376.400,00 kn - HRK | IBAN: HR8623400091100139701| Direktor društva : Igor Kruljac							
								</xsl:when>
								<xsl:otherwise>
INA – Industrija nafte, d.d. | Avenija Većeslava Holjevca 10 | p.p. 555 | 10 002 Zagreb | Hrvatska | Trgovački sud u Zagrebu | MBS: 080000604 | OIB - 27759560625 | Uplaćen temeljni kapital | 9.000.000.000, 00 kn - HRK | Broj izdanih dionica / Nominalna vrijednost 10.000.000 / 900, 00 kn - HRK Matični broj – Reg.No. 3586243								
								</xsl:otherwise>
								
							</xsl:choose>
							

							</ext:InvoiceIssuer>
						</ext:ExtensionContent>
					</ext:UBLExtension>


				<xsl:apply-templates select="/i:Invoice/ext:UBLExtensions//ihi:IssuePlace" mode="UBLExtension" />
				<xsl:apply-templates select="/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm" mode="UBLExtension" />
			
			</ext:UBLExtensions>
			<cbc:UBLVersionID>2.1</cbc:UBLVersionID>
			<cbc:CustomizationID>
				<xsl:value-of select="'urn:invoice.hr:ubl-2.1-customizations:FinaInvoice'"/>
			</cbc:CustomizationID>

			<!--<xsl:apply-templates select="cbc:ProfileID" />-->
			<cbc:ProfileID>MojEracunInvoice</cbc:ProfileID>
			<xsl:apply-templates select="cbc:ID" mode="FiscalNumber" />
			<xsl:apply-templates select="cbc:CopyIndicator" />
			<xsl:apply-templates select="cbc:IssueDate" />
			<!--<xsl:apply-templates select="cbc:Note" mode="IssueTime" />-->
			<xsl:if test="normalize-space($issueTime) != ''">
				<cbc:IssueTime><xsl:value-of select="$issueTime" /></cbc:IssueTime>
			</xsl:if>

			<!--<xsl:apply-templates select="cac:PaymentMeans/cbc:PaymentDueDate" />-->
			<xsl:apply-templates select="cbc:InvoiceTypeCode" />
			<xsl:apply-templates select="cbc:Note" />
			<xsl:apply-templates select="cbc:TaxPointDate" />
			<xsl:apply-templates select="cbc:DocumentCurrencyCode" />
			<xsl:apply-templates select="cbc:TaxCurrencyCode" />
			<xsl:apply-templates select="cbc:AccountingCost" />
			<xsl:apply-templates select="cbc:BuyerReference" />
			<xsl:apply-templates select="cac:InvoicePeriod" />
			
			<xsl:apply-templates select="cac:OrderReference" />
			<xsl:apply-templates select="cac:BillingReference" />
			<xsl:apply-templates select="cac:DespatchDocumentReference" />			
			<xsl:apply-templates select="cac:ReceiptDocumentReference" />
			<xsl:apply-templates select="cac:OriginatorDocumentReference" />
			<xsl:apply-templates select="cac:ContractDocumentReference" />
			<xsl:apply-templates select="cac:AdditionalDocumentReference" />
			<xsl:if test="normalize-space($SAPTypeID) != ''">
			<xsl:apply-templates select="cac:AdditionalDocumentReference" mode="SapTypeID" />
			</xsl:if>
			<xsl:apply-templates select="cac:AccountingSupplierParty" />
			<xsl:apply-templates select="cac:AccountingCustomerParty" />
			
			<xsl:apply-templates select="cac:PayeeParty" />
			<xsl:apply-templates select="cac:TaxRepresentativeParty" />
			
			<xsl:apply-templates select="cac:Delivery" />
			
			<xsl:apply-templates select="cac:PaymentMeans" />
			<xsl:apply-templates select="cac:PaymentTerms" />
			
			<xsl:apply-templates select="cac:AllowanceCharge" />
			
			<xsl:apply-templates select="cac:TaxTotal" />
			<xsl:apply-templates select="cac:LegalMonetaryTotal" />

			<xsl:apply-templates select="cac:InvoiceLine" />
		</xsl:copy>
		
<!--		</Invoice>-->
	
	</xsl:template>
	
	<xsl:template match="cac:InvoiceLine">
		<cac:InvoiceLine>
			<xsl:apply-templates select="cbc:ID" mode="ID"/>
			<xsl:apply-templates select="cbc:Note" />
			<xsl:apply-templates select="cbc:InvoicedQuantity" />
			<xsl:apply-templates select="cbc:LineExtensionAmount" />
			<xsl:apply-templates select="cbc:AccountingCost" />
			<xsl:apply-templates select="cac:InvoicePeriod" mode="InvoiceLine" />
			<xsl:apply-templates select="cac:OrderLineReference" mode="InvoiceLine"/>
			<xsl:apply-templates select="cac:DespatchLineReference" mode="InvoiceLine"/>
			<xsl:apply-templates select="cac:DocumentReference" mode="InvoiceLine"/>
			<xsl:apply-templates select="cac:Delivery"/>
			<xsl:apply-templates select="cac:AllowanceCharge" mode="InvoiceLine" />
			
			<!--<xsl:apply-templates select="cac:Item/cac:TaxCategory" mode="AllowanceChargeLine" />
			<xsl:variable name="taxCategoryNode">
				<xsl:apply-templates select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory" mode="AllowanceChargeLine" />
			</xsl:variable>
			
			<xsl:variable name="currencyID"><xsl:value-of select="cbc:LineExtensionAmount/@currencyID" /></xsl:variable>
			<xsl:variable name="taxableAmount"><xsl:value-of select="number(cbc:LineExtensionAmount)" /></xsl:variable>
			<xsl:variable name="percent"><xsl:value-of select="number(cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent)" /></xsl:variable>
			-->
			<xsl:call-template name="HRTaxTotal">
				<xsl:with-param name="currencyID" select="cbc:LineExtensionAmount/@currencyID" />
				<xsl:with-param name="taxableAmount" select="cbc:LineExtensionAmount"/>
				<xsl:with-param name="percent" select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent"/>		
				<xsl:with-param name="taxCategoryID" select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:ID" />
			</xsl:call-template>

			<xsl:apply-templates select="cac:Item" mode="InvoiceLine" />
			<xsl:apply-templates select="cac:Price" mode="InvoiceLine" />
			

		</cac:InvoiceLine>
		
	</xsl:template>	
	
	<xsl:template match="cac:Price" mode="InvoiceLine" >
		<cac:Price>
			<xsl:apply-templates select="cbc:PriceAmount" />
			<xsl:apply-templates select="cbc:BaseQuantity" />
			<xsl:apply-templates select="cac:AllowanceCharge" mode="Price" />
		</cac:Price>
	
	</xsl:template>
	
	<xsl:template match="cac:AllowanceCharge" mode="Price" >
		<cac:AllowanceCharge>
			<cbc:ChargeIndicator>false</cbc:ChargeIndicator>
			<xsl:apply-templates select="cbc:Amount" />
			<xsl:apply-templates select="cbc:BaseAmount" />
			
		</cac:AllowanceCharge>
	
	</xsl:template>

	
	<xsl:template match="cbc:BaseQuantity" >
		<cbc:BaseQuantity>
			<xsl:attribute name="unitCode" namespace="" >
				<xsl:value-of select="@unitCode" />
			</xsl:attribute>
			
			<xsl:value-of select="number(.)" />
		</cbc:BaseQuantity>
	
	</xsl:template>

	<xsl:template match="cac:Item" mode="InvoiceLine">
		<cac:Item>
			<xsl:apply-templates select="cbc:Description" />
			<xsl:apply-templates select="cbc:PackQuantity" />
			<xsl:apply-templates select="cbc:PackSizeNumeric" />
			<xsl:apply-templates select="cbc:Name" />
			<xsl:apply-templates select="cac:BuyersItemIdentification" />
			<xsl:apply-templates select="cac:SellersItemIdentification" />
			<xsl:apply-templates select="cac:ManufacturersItemIdentification" />
			<xsl:apply-templates select="cac:StandardItemIdentification" />
			<xsl:apply-templates select="cac:AdditionalItemIdentification" />

			<xsl:apply-templates select="cac:OriginCountry" />
			<xsl:apply-templates select="cac:CommodityClassification" />
			<!--<xsl:apply-templates select="../cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory" mode="InvoiceLine" />AllowanceChargeLine-->
			<xsl:apply-templates select="cac:AdditionalItemProperty[not((cbc:Name/text() = 'ManufacturersItemIdentification') or (cbc:Name/text() = 'AdditionalItemIdentification'))]" />
			
			
			
		</cac:Item>
	
	</xsl:template>
	
	<xsl:template match="cac:AdditionalItemProperty">
		<xsl:if test="normalize-space(.) != ''" >
			<cac:AdditionalItemProperty>
				<xsl:apply-templates select="cbc:Name" />
				<xsl:apply-templates select="cbc:Value" />
			
			</cac:AdditionalItemProperty>
		</xsl:if>	
	</xsl:template>
	
	<xsl:template match="cac:ManufacturersItemIdentification">
		<cac:ManufacturersItemIdentification>
			<cbc:ID><xsl:value-of select="cbc:Value" /></cbc:ID>
		
		</cac:ManufacturersItemIdentification>
	</xsl:template>

	<xsl:template match="cac:AdditionalItemProperty" mode="AdditionalItemIdentification">
		<cac:AdditionalItemIdentification>
			<cbc:ID><xsl:value-of select="cbc:Value" /></cbc:ID>
		
		</cac:AdditionalItemIdentification>
	</xsl:template>
	<xsl:template match="cbc:ID" mode="HeaderFiscalNumber">
		<DocumentID xmlns="http://ubl.moj-eracun.hr/v1.2/xsd">
			<xsl:choose>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '15538072333'">
					<xsl:choose>
						<xsl:when test="contains(.,'RIZ')">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="contains(../cac:AdditionalDocumentReference/cbc:ID,'RIZ')">
									<xsl:value-of select="../cac:AdditionalDocumentReference/cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '99172175603'">
					<xsl:choose>
						<xsl:when test="contains(.,'STSI')">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="contains(../cac:AdditionalDocumentReference/cbc:ID,'STSI')">
									<xsl:value-of select="../cac:AdditionalDocumentReference/cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>
		</DocumentID>
	</xsl:template>
	<xsl:template match="cbc:ID" mode="FiscalNumber">
		<cbc:ID>
			<xsl:choose>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '15538072333'">
					<xsl:choose>
						<xsl:when test="contains(.,'RIZ')">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="contains(../cac:AdditionalDocumentReference/cbc:ID,'RIZ')">
									<xsl:value-of select="../cac:AdditionalDocumentReference/cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '99172175603'">
					<xsl:choose>
						<xsl:when test="contains(.,'STSI')">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="contains(../cac:AdditionalDocumentReference/cbc:ID,'STSI')">
									<xsl:value-of select="../cac:AdditionalDocumentReference/cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>
		</cbc:ID>
	</xsl:template>
<!--	<xsl:template match="cac:TaxCategory" mode="InvoiceLine">
		<cac:ClassifiedTaxCategory>
			<xsl:choose>
				<xsl:when test="$isOutsideVAT = 'true'">
					<cbc:ID>O</cbc:ID>
				</xsl:when>
				<xsl:otherwise>
					<xsl:apply-templates select="cbc:ID" mode="TaxCategoryID" />
					<xsl:apply-templates select="cbc:Percent" />
					
				</xsl:otherwise>
			</xsl:choose>
			
			<cac:TaxScheme>
				<cbc:ID>VAT</cbc:ID>
			</cac:TaxScheme>
		
		</cac:ClassifiedTaxCategory>
	
	</xsl:template>
-->
	
	<xsl:template match="cac:CommodityClassification" >
		<cac:CommodityClassification>
			<xsl:apply-templates select="cbc:ItemClassificationCode" />
		</cac:CommodityClassification>
	
	</xsl:template>
	
	<xsl:template match="cbc:ItemClassificationCode" >
		<cbc:ItemClassificationCode>
			<xsl:attribute name="listID">
				<xsl:value-of select="@listID" />
			</xsl:attribute>
			<xsl:attribute name="listVersionID">
				<xsl:value-of select="@listVersionID" />
			</xsl:attribute>
			<xsl:value-of select="." />
			
		</cbc:ItemClassificationCode>
	
	</xsl:template>
	
	<xsl:template match="cac:OriginCountry" >
		<cac:OriginCountry>
			<xsl:apply-templates select="cbc:IdentificationCode" />
		</cac:OriginCountry>
	</xsl:template>
	
	<xsl:template match="cac:StandardItemIdentification | cac:AdditionalItemIdentification">
		<xsl:if test="cbc:ID and (normalize-space(cbc:ID) != '')" >
			<cac:AdditionalItemIdentification>
				<xsl:apply-templates select="cbc:ID" mode="SchemeID" />
			</cac:AdditionalItemIdentification>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="cac:SellersItemIdentification">
		<cac:SellersItemIdentification>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:SellersItemIdentification>
	</xsl:template>
	
	<xsl:template match="cac:BuyersItemIdentification">
		<cac:BuyersItemIdentification>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:BuyersItemIdentification>
	</xsl:template>
	
	<xsl:template match="cac:AllowanceCharge" mode="InvoiceLine" >
		<cac:AllowanceCharge>
			<xsl:apply-templates select="cbc:ChargeIndicator" />
			<xsl:apply-templates select="cbc:AllowanceChargeReasonCode" />
			<xsl:apply-templates select="cbc:AllowanceChargeReason" />
			<xsl:apply-templates select="cbc:MultiplierFactorNumeric" />
			<xsl:apply-templates select="cbc:Amount" />
			<xsl:apply-templates select="cbc:BaseAmount" />

<!--		<xsl:variable name="taxCategoryNode">
				<xsl:apply-templates select="../cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory" mode="AllowanceChargeLine" />
			</xsl:variable>

			<xsl:variable name="currencyID"><xsl:value-of select="cbc:Amount/@currencyID" /></xsl:variable>
			<xsl:variable name="taxableAmount"><xsl:value-of select="number(cbc:Amount)" /></xsl:variable>
			<xsl:variable name="percent"><xsl:value-of select="number(../cac:Item/cac:ClassifiedTaxCategory/cbc:Percent)" /></xsl:variable>-->
			<xsl:call-template name="HRTaxTotal">
				<xsl:with-param name="currencyID" select="cbc:Amount/@currencyID" />
				<xsl:with-param name="taxableAmount" select="cbc:Amount"/>
				<xsl:with-param name="percent" select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent"/>		
				<xsl:with-param name="taxCategoryID" select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:ID" />
			</xsl:call-template>
		</cac:AllowanceCharge>
			

	
	</xsl:template>
	
	<xsl:template match="cac:TaxCategory" mode="AllowanceChargeLine">
		<xsl:variable name="taxExemptionReason">
			<xsl:variable name="taxCategoryID">
				<xsl:call-template name="HRTaxCategoyIDValue">
					<xsl:with-param name="taxCategoryID" select="cbc:ID" />
				</xsl:call-template>
			</xsl:variable>
			<xsl:apply-templates select="/i:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:ID/text() = $taxCategoryID]/cbc:TaxExemptionReason" />
		</xsl:variable>
		
		<xsl:call-template name="HRTaxCategory">
			<xsl:with-param name="taxCategoryID" select="cbc:ID" />
			<xsl:with-param name="percent" select="cbc:Percent" />	
			<xsl:with-param name="taxExemption"	select="$taxExemptionReason" />
		</xsl:call-template>
			
<!--		<cac:TaxCategory>
			<xsl:variable name="taxCategoryID">
				<xsl:call-template name="HRTaxCategoyIDValue">
					<xsl:with-param name="taxCategoryID" select="cbc:ID" />
				</xsl:call-template>
			</xsl:variable>
			<xsl:call-template name="HRTaxCategoryID">
				<xsl:with-param name="taxCategoryID" select="$taxCategoryID" />
			</xsl:call-template>
			--><!--<xsl:apply-templates select="cbc:Percent" />--><!--
			<xsl:choose>
				<xsl:when test="cbc:Percent and (string(number(cbc:Percent)) != 'NaN')">
					<xsl:apply-templates select="cbc:Percent" />
				</xsl:when>
				<xsl:otherwise>
					<cbc:Percent>0</cbc:Percent>
				</xsl:otherwise>
			</xsl:choose>
			
			<xsl:apply-templates select="/i:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:ID/text() = $taxCategoryID]/cbc:TaxExemptionReason" />
			
			<xsl:call-template name="HRTaxScheme">
				<xsl:with-param name="percent" select="cbc:Percent" />			
			</xsl:call-template>
		
		</cac:TaxCategory>
-->	
	</xsl:template>


	<xsl:template match="cac:DocumentReference" mode="InvoiceLine">
		<xsl:if test="cbc:ID and (normalize-space(cbc:ID) != '')" >
			<cac:DocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="SchemeID"/>
			</cac:DocumentReference>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="cac:DespatchLineReference" mode="InvoiceLine">
	
	<!--TODO: vidjeti da li staviti neko drugo mapiranje - Vindija navodi Order/cbc:ID-->
		<xsl:if test="cbc:LineID and (normalize-space(cbc:LineID) != '')" >
			<cac:DespatchLineReference>
				<xsl:apply-templates select="cbc:LineID" />
				<xsl:apply-templates select="cac:DocumentReference" mode = "InvoiceLine"/>
			</cac:DespatchLineReference>
		</xsl:if>
	</xsl:template>
	
	
	<xsl:template match="cac:OrderLineReference" mode="InvoiceLine">
	
	<!--TODO: vidjeti da li staviti neko drugo mapiranje - Vindija navodi Order/cbc:ID-->
		<xsl:if test="cbc:LineID and (normalize-space(cbc:LineID) != '')" >
			<cac:OrderLineReference>
				<xsl:apply-templates select="cbc:LineID" />
			</cac:OrderLineReference>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="cac:InvoicePeriod" mode="InvoiceLine">
		<xsl:if test="normalize-space(.) != ''" >
			<cac:InvoicePeriod>
				<xsl:apply-templates select="cbc:StartDate" />
				<xsl:apply-templates select="cbc:EndDate" />
			
			</cac:InvoicePeriod>
		</xsl:if>
	</xsl:template>

	
	<xsl:template match="cbc:InvoicedQuantity">
		<cbc:InvoicedQuantity>
			<xsl:attribute name="unitCode" namespace="">
				<xsl:value-of select="@unitCode" />
			</xsl:attribute>
			<xsl:value-of select="number(.)" />
			
		</cbc:InvoicedQuantity>
	</xsl:template>
	
	<xsl:template match="cac:TaxTotal">
	
		<cac:TaxTotal>
			<xsl:apply-templates select="cbc:TaxAmount" />
			<xsl:apply-templates select="cac:TaxSubtotal" mode="TaxTotal" />
		
		</cac:TaxTotal>
	
	
	</xsl:template>
	
	
	
	<xsl:template match="cac:TaxSubtotal" mode="TaxTotal" >
		<cac:TaxSubtotal>
			<xsl:apply-templates select="cbc:TaxableAmount" />
			<xsl:apply-templates select="cbc:TaxAmount" />
			<xsl:apply-templates select="cac:TaxCategory" mode="TaxTotal" />
		
		</cac:TaxSubtotal>
	
	</xsl:template>
	
	<xsl:template match="cac:TaxCategory" mode="TaxTotal">
	
		<xsl:variable name="taxExemptionReason">
			<xsl:apply-templates select="cbc:TaxExemptionReasonCode" />
			<xsl:apply-templates select="cbc:TaxExemptionReason" />		
		</xsl:variable>
		
		<xsl:call-template name="HRTaxCategory">
			<xsl:with-param name="taxCategoryID" select="cbc:ID" />
			<xsl:with-param name="percent" select="cbc:Percent" />	
			<xsl:with-param name="taxExemption"	select="$taxExemptionReason" />
		</xsl:call-template>
	
	
	</xsl:template>

<!--	<xsl:template match="cac:TaxCategory" mode="TaxTotal" >
		<cac:TaxCategory>
			--><!--<xsl:apply-templates select="cbc:ID" mode="TaxCategoryID" />--><!--
			<xsl:call-template name="HRTaxCategoryID">
				<xsl:with-param name="taxCategoryID" select="cbc:ID" />
			</xsl:call-template>
			<xsl:choose>
				<xsl:when test="cbc:Percent and (string(number(cbc:Percent)) != 'NaN')">
					<xsl:apply-templates select="cbc:Percent" />
				</xsl:when>
				<xsl:otherwise>
					<cbc:Percent>0</cbc:Percent>
				</xsl:otherwise>
			</xsl:choose>
			
						
			<xsl:apply-templates select="cbc:TaxExemptionReasonCode" />
			<xsl:apply-templates select="cbc:TaxExemptionReason" />
			
			<xsl:call-template name="HRTaxScheme">
				<xsl:with-param name="percent" select="cbc:Percent" />			
			</xsl:call-template>
		
		</cac:TaxCategory>

	</xsl:template>-->

	
	<xsl:template match="cac:AllowanceCharge">
		<xsl:variable name="percent"><xsl:value-of select=".//cac:TaxCategory/cbc:Percent" /></xsl:variable>
		<xsl:if test="(//i:Invoice/cac:TaxTotal//cac:TaxCategory/cbc:Percent[number(text()) = number($percent)] ) or (number(cbc:Amount) > 0)" >
			<cac:AllowanceCharge>
				<xsl:apply-templates select="cbc:ChargeIndicator" />
				<xsl:apply-templates select="cbc:AllowanceChargeReasonCode" />
				<xsl:apply-templates select="cbc:AllowanceChargeReason" />
				<xsl:apply-templates select="cbc:MultiplierFactorNumeric" />
				<xsl:apply-templates select="cbc:Amount" />
				<xsl:apply-templates select="cbc:BaseAmount" />
				
	<!--			<xsl:choose>
					<xsl:when test="cac:TaxCategory">
						<xsl:apply-templates select="cac:TaxCategory" mode="AllowanceCharge" />
					</xsl:when>
					<xsl:when test="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory">
						<xsl:apply-templates select="cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory" mode="AllowanceCharge" />
					</xsl:when>
				</xsl:choose>
		
				<xsl:variable name="taxCategoryNode">
					<xsl:apply-templates select="cac:TaxCategory" mode="AllowanceCharge" />
				</xsl:variable>
	-->					
				<xsl:variable name="currencyID">
					<xsl:choose>
						<xsl:when test="normalize-space(cbc:Amount/@currencyID) != ''">
							<xsl:value-of select="cbc:Amount/@currencyID" />
						</xsl:when>
						<xsl:otherwise>HRK</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>	
	<!--		<xsl:variable name="taxableAmount"><xsl:value-of select="number(cbc:Amount)" /></xsl:variable>
				<xsl:variable name="percent"><xsl:value-of select="number(cac:TaxCategory/cbc:Percent)" /></xsl:variable>
	-->
	<!--			<xsl:call-template name="HRTaxTotal">
					<xsl:with-param name="currencyID" select="$currencyID" />
					<xsl:with-param name="taxableAmount" select="cbc:Amount"/>
					<xsl:with-param name="percent" select="cac:TaxCategory/cbc:Percent"/>	
					<xsl:with-param name="taxCategoryID" select="cac:TaxCategory/cbc:ID" />
				</xsl:call-template>
	-->
				<xsl:variable name="taxExemptionReason">
					<xsl:apply-templates select="cac:TaxCategory/cbc:TaxExemptionReasonCode" />
					<xsl:apply-templates select="cac:TaxCategory/cbc:TaxExemptionReason" />		
				</xsl:variable>
				
				<xsl:call-template name="HRTaxCategory">
					<xsl:with-param name="taxCategoryID" select="cac:TaxCategory/cbc:ID" />
					<xsl:with-param name="percent" select="cac:TaxCategory/cbc:Percent" />	
					<xsl:with-param name="taxExemption"	select="$taxExemptionReason" />
				</xsl:call-template>
			</cac:AllowanceCharge>
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="HRTaxTotal">
		<xsl:param name="currencyID" select="'HRK'" />
		<xsl:param name="taxableAmount" select="0.00"/>
		<xsl:param name="percent" select="0"/>
		<xsl:param name="taxCategoryID" />
			<!--<xsl:value-of select="concat('cID', $currencyID , 'taAm', $taxableAmount, 'per', $percent)" />-->
			<cac:TaxTotal>
				<xsl:variable name="taxAmount">
					<xsl:choose>
						<xsl:when test="string(number(number($taxableAmount) * number($percent) div 100))='NaN'">0.00</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="format-number( number($taxableAmount) * number($percent) div 100, '#0.00') " />
						</xsl:otherwise>
					</xsl:choose>
				</xsl:variable>
				<cbc:TaxAmount>
					 <xsl:attribute name="currencyID"><xsl:value-of select="$currencyID" /></xsl:attribute>
					<xsl:value-of select="$taxAmount" />					 
				 </cbc:TaxAmount>
				 <cac:TaxSubtotal>
					 <cbc:TaxableAmount>
						 <xsl:attribute name="currencyID"><xsl:value-of select="$currencyID" /></xsl:attribute>
						 <xsl:choose>
							<xsl:when test="string(number($taxableAmount))='NaN'">0.00</xsl:when>
							<xsl:otherwise>
								<xsl:value-of select="format-number( number($taxableAmount), '#0.00') " />
							</xsl:otherwise>
						</xsl:choose>
					 </cbc:TaxableAmount>
					 <cbc:TaxAmount>
						 <xsl:attribute name="currencyID"><xsl:value-of select="$currencyID" /></xsl:attribute>
						 <xsl:value-of select="$taxAmount" />
					 </cbc:TaxAmount>
					<cbc:CalculationSequenceNumeric>1</cbc:CalculationSequenceNumeric>
					<!--<xsl:apply-templates select="cac:TaxCategory" mode="AllowanceChargeLine" />-->
					<xsl:call-template name="HRTaxCategory">
						<xsl:with-param name="taxCategoryID" select="$taxCategoryID" />
						<xsl:with-param name="percent" select="$percent" />
					
					</xsl:call-template>
					
				 </cac:TaxSubtotal>
			</cac:TaxTotal>
	
	</xsl:template>
	
	<xsl:template name="HRTaxCategory">
		<xsl:param name="taxCategoryID" />
		<xsl:param name="percent" />
		<xsl:param name="taxExemption" />

		<xsl:choose>
			<xsl:when test="(normalize-space($taxCategoryID) != '') and 
			(normalize-space($taxCategoryID) != 'S' ) and (normalize-space($taxCategoryID) != 'E')">
				<cac:TaxCategory>
					<xsl:call-template name="HRTaxCategoryID">
						<xsl:with-param name="taxCategoryID"><xsl:value-of select="$taxCategoryID" /></xsl:with-param>
					
					</xsl:call-template>
					<xsl:call-template name="HRTaxPercent">
						<xsl:with-param name="percent" select="$percent" />
					</xsl:call-template>
					
					<xsl:if test="normalize-space($taxExemption) != ''" >
						<xsl:copy-of select="$taxExemption" />
					</xsl:if>
					
					<xsl:call-template name="HRTaxScheme">
						<xsl:with-param name="percent" select="$percent" />				
					</xsl:call-template>
				</cac:TaxCategory>
			</xsl:when>
			<xsl:when test="normalize-space(string($percent)) != ''">
				<cac:TaxCategory>
					<xsl:choose>
						<xsl:when test="number($percent) = 0">
							<xsl:call-template name="HRTaxCategoryID">
								<xsl:with-param name="taxCategoryID">E</xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="HRTaxCategoryID">
								<xsl:with-param name="taxCategoryID">S</xsl:with-param>
							</xsl:call-template>
						</xsl:otherwise>
					</xsl:choose>

					<xsl:call-template name="HRTaxPercent">
						<xsl:with-param name="percent" select="$percent" />
					</xsl:call-template>

					<xsl:if test="normalize-space($taxExemption) != ''" >
						<xsl:copy-of select="$taxExemption" />
					</xsl:if>
					
					
					<xsl:call-template name="HRTaxScheme">
						<xsl:with-param name="percent" select="$percent" />				
					</xsl:call-template>
				</cac:TaxCategory>
			</xsl:when>
			<xsl:otherwise>	
				<cac:TaxCategory>
					<cbc:ID schemeID="UN/ECE 5305" schemeAgencyID="6" schemeURI="http://www.unece.org/trade/untdid/d07a/tred/tred5305.htm">S</cbc:ID>
					<cbc:Name>PDV</cbc:Name>
					<xsl:call-template name="HRTaxPercent">
						<xsl:with-param name="percent" select="$_defStandardnaStopaPDV" />
					</xsl:call-template>
					<xsl:call-template name="HRTaxScheme">
						<xsl:with-param name="percent" select="$_defStandardnaStopaPDV" />
					</xsl:call-template>
				</cac:TaxCategory>
			</xsl:otherwise>
		</xsl:choose>
	
	</xsl:template>
	
	<xsl:template name="HRTaxPercent" >
		<xsl:param name="percent" />

		<xsl:choose>
			<!--<xsl:when test="cbc:Percent and (string(number($percent)) != 'NaN')">-->
			<xsl:when test="string(number($percent)) != 'NaN'">

				<cbc:Percent><xsl:value-of select="number($percent)" /></cbc:Percent>
			</xsl:when>
			<xsl:otherwise>
				<cbc:Percent>0</cbc:Percent>
			</xsl:otherwise>
		</xsl:choose>
	
	</xsl:template>
	
	
	<xsl:template match="cac:LegalMonetaryTotal">
		<cac:LegalMonetaryTotal>
			<xsl:apply-templates select="cbc:LineExtensionAmount" />
			<xsl:apply-templates select="cbc:TaxExclusiveAmount" />
			<xsl:apply-templates select="cbc:TaxInclusiveAmount" />
			<!--<xsl:apply-templates select="cbc:AllowanceTotalAmount" />-->
			<xsl:call-template name="AllowanceTotalAmount" />
			<xsl:apply-templates select="cbc:ChargeTotalAmount" />
			<xsl:apply-templates select="cbc:PrepaidAmount" />
			<xsl:apply-templates select="cbc:PayableRoundingAmount" />
			<xsl:apply-templates select="cbc:PayableAmount" />
		
		</cac:LegalMonetaryTotal>
	
	</xsl:template>
	
	<xsl:template name="AllowanceTotalAmount" >
		<xsl:choose>
			<xsl:when test="cbc:AllowanceTotalAmount"><xsl:apply-templates select="cbc:AllowanceTotalAmount" /></xsl:when>
			<xsl:otherwise><cbc:AllowanceTotalAmount currencyID="HRK">0.00</cbc:AllowanceTotalAmount></xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	
	<xsl:template name="HRTaxCategoryID">
		<xsl:param name="taxCategoryID" />
		<cbc:ID schemeID="UN/ECE 5305" schemeAgencyID="6" schemeURI="http://www.unece.org/trade/untdid/d07a/tred/tred5305.htm">
			<xsl:choose>
				<xsl:when test="normalize-space($taxCategoryID) != ''"><xsl:value-of select="$taxCategoryID" /></xsl:when>
				<xsl:otherwise>S</xsl:otherwise>
			</xsl:choose>
		
		</cbc:ID>
		<cbc:Name>
			<xsl:choose>
				<xsl:when test="$taxCategoryID = 'S'">PDV</xsl:when>
				<xsl:when test="$taxCategoryID = 'O'">NEOPOREZIVO</xsl:when>
				<xsl:when test="$taxCategoryID = 'AE'">PPO</xsl:when>
				<xsl:when test="$taxCategoryID = 'E'">OSLOBOĐENO_POREZA</xsl:when>
				<xsl:when test="normalize-space($taxCategoryID) != ''"><xsl:value-of select="$taxCategoryID" /></xsl:when>
				<xsl:otherwise>PDV</xsl:otherwise>
			</xsl:choose>
		</cbc:Name>
	</xsl:template>
	
	<xsl:template name="HRTaxCategoyIDValue">
		<xsl:param name="taxCategoryID" />
				<xsl:choose>
					<!--Podrška za mapping ako bude potreban -->
					<xsl:when test="normalize-space($taxCategoryID) = 'O'">O</xsl:when>
					<xsl:when test="normalize-space($taxCategoryID) = 'E'">E</xsl:when>
					<xsl:otherwise><xsl:value-of select="$taxCategoryID" /></xsl:otherwise>
				</xsl:choose>	
	</xsl:template>
	
	
	<xsl:template match="cac:TaxCategory" mode="AllowanceCharge">
		
		<xsl:variable name="taxExemptionReason">
			<xsl:variable name="taxCategoryID">
				<xsl:call-template name="HRTaxCategoyIDValue">
					<xsl:with-param name="taxCategoryID" select="cbc:ID" />
				</xsl:call-template>
			</xsl:variable>
			<xsl:apply-templates select="/i:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:ID/text() = $taxCategoryID]/cbc:TaxExemptionReason" />
		</xsl:variable>
		
		<xsl:call-template name="HRTaxCategory">
			<xsl:with-param name="taxCategoryID" select="cbc:ID" />
			<xsl:with-param name="percent" select="cbc:Percent" />	
			<xsl:with-param name="taxExemption"	select="$taxExemptionReason" />
		</xsl:call-template>
	

<!--		<cac:TaxCategory>
			<xsl:variable name="taxCategoryID">
				<xsl:call-template name="HRTaxCategoyIDValue">
					<xsl:with-param name="taxCategoryID" select="cbc:ID" />
				</xsl:call-template>
			</xsl:variable>
			<xsl:call-template name="HRTaxCategoryID">
				<xsl:with-param name="taxCategoryID" select="$taxCategoryID" />
			</xsl:call-template>
			<xsl:apply-templates select="cbc:Percent" />
			
			<xsl:apply-templates select="/i:Invoice/cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory[cbc:ID/text() = $taxCategoryID]/cbc:TaxExemptionReason" />
			
			<xsl:call-template name="HRTaxScheme">
				<xsl:with-param name="percent" select="cbc:Percent" />			
			</xsl:call-template>
		
		</cac:TaxCategory>
-->	
	</xsl:template>

	<xsl:template name="HRTaxScheme">
		<xsl:param name="percent" select="0"/>
			<xsl:choose>
				<xsl:when test="number($percent) = 0">
					<cac:TaxScheme>
						<cbc:Name>FRE</cbc:Name>
						<cbc:TaxTypeCode listAgencyName="RH" listName="taxtypecode" listVersionID="1.1" listURI="http://cv.eracun.hr/ubl/os-ubl-2.0/cl/gc/taxtypecode" listSchemeURI="urn:hrubl:codelist:taxtypecode-1.1">ZeroRated</cbc:TaxTypeCode>
					</cac:TaxScheme>		
				</xsl:when>
				<xsl:when test="string(number($percent)) = 'NaN'">
					<cac:TaxScheme>
						<cbc:Name>FRE</cbc:Name>
						<cbc:TaxTypeCode listAgencyName="RH" listName="taxtypecode" listVersionID="1.1" listURI="http://cv.eracun.hr/ubl/os-ubl-2.0/cl/gc/taxtypecode" listSchemeURI="urn:hrubl:codelist:taxtypecode-1.1">ZeroRated</cbc:TaxTypeCode>
					</cac:TaxScheme>		
				</xsl:when>
				<xsl:otherwise>
					<cac:TaxScheme>
						<cbc:Name>VAT</cbc:Name>
						<cbc:TaxTypeCode listAgencyName="RH" listName="taxtypecode" listVersionID="1.1" listURI="http://cv.eracun.hr/ubl/os-ubl-2.0/cl/gc/taxtypecode" listSchemeURI="urn:hrubl:codelist:taxtypecode-1.1">StandardRated</cbc:TaxTypeCode>
					</cac:TaxScheme>
				
				</xsl:otherwise>
			</xsl:choose>
	
	</xsl:template>
	
	
	<xsl:template match="cac:PaymentTerms" >
		<cac:PaymentTerms>
			<cbc:ID><xsl:value-of select="concat('PT-', position())" /></cbc:ID>
			<cbc:PaymentMeansID>PM-001</cbc:PaymentMeansID>
			<xsl:apply-templates select="cbc:Note" />
			<xsl:apply-templates select="//cac:LegalMonetaryTotal/cbc:PayableAmount" mode="PaymentTermsAmount" />
		</cac:PaymentTerms>
	
	</xsl:template>
	
	<xsl:template match="cbc:PayableAmount" mode="PaymentTermsAmount" >
		<cbc:Amount>
			<xsl:attribute name="currencyID" namespace="" >
				<xsl:value-of select="@currencyID" />
			</xsl:attribute>
			<xsl:value-of select="." />
		</cbc:Amount>
		
	</xsl:template>
	
	<xsl:template match="cac:PaymentMeans" >
		<cac:PaymentMeans>
			<cbc:ID>PM-001</cbc:ID>
			<xsl:apply-templates select="cbc:PaymentMeansCode" />
			<xsl:apply-templates select="cbc:PaymentDueDate" />
			<xsl:apply-templates select="cbc:PaymentChannelCode" />
			
			<xsl:call-template name="PaymentID" />
			<xsl:apply-templates select="cbc:InstructionNote" />
			
			<xsl:call-template name="InstructionID" />
			<xsl:apply-templates select="cac:PayeeFinancialAccount" mode="PaymentMeans" />

			
		
		</cac:PaymentMeans>
	
	</xsl:template>
	

	
	<xsl:template match="cbc:DocumentCurrencyCode" mode="CurrencyCode" >
	
		<cbc:CurrencyCode listID="ISO 4217 Alpha" listAgencyID="5" listURI="http://docs.oasis-open.org/ubl/os-UBL-2.1/cl/gc/default/CurrencyCode-2.1.gc">
			<xsl:value-of select="." />
		</cbc:CurrencyCode>
	</xsl:template>
	
	<xsl:template match="cac:PayeeFinancialAccount" mode="PaymentMeans">
		<cac:PayeeFinancialAccount>
			<xsl:apply-templates select="cbc:ID" />
			<xsl:apply-templates select="/i:Invoice/cbc:DocumentCurrencyCode" mode="CurrencyCode" />
			<xsl:apply-templates select="cbc:Name" />
			<xsl:apply-templates select="cac:FinancialInstitutionBranch" />
		
		</cac:PayeeFinancialAccount>
	
	</xsl:template>
	

	
	<xsl:template match="cac:FinancialInstitutionBranch">
		<cac:FinancialInstitutionBranch>
			<cac:FinancialInstitution>
				<xsl:apply-templates select="cac:FinancialInstitution/cbc:ID" />
				<xsl:apply-templates select="cac:FinancialInstitution/cbc:Name" />
			</cac:FinancialInstitution>
		</cac:FinancialInstitutionBranch>
	
	</xsl:template>
	
	<xsl:template match="cac:CardAccount" >
		<cac:CardAccount>
			<xsl:apply-templates select="cbc:PrimaryAccountNumberID" />
			<xsl:apply-templates select="cbc:NetworkID" />
			<xsl:apply-templates select="cbc:HolderName" />
		
		</cac:CardAccount>
	
	</xsl:template>
	
	<xsl:template name="PaymentID" >
		<cbc:InstructionID>
			<xsl:value-of select="normalize-space(cbc:PaymentID)" />
		
		</cbc:InstructionID>
	
	</xsl:template>

	
	<xsl:template name="InstructionID" >
		<cbc:PaymentID>
			<xsl:value-of select="normalize-space(cbc:InstructionID)" />
		</cbc:PaymentID>
	
	</xsl:template>
	
	<xsl:template match="cbc:PaymentChannelCode">
		<cbc:PaymentChannelCode listAgencyName="CEN/BII">
			<xsl:choose>
				<xsl:when test="normalize-space(.) = ''">IBAN</xsl:when>
				<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
			</xsl:choose>		
		
		</cbc:PaymentChannelCode>
	
	</xsl:template>
	
	<xsl:template match="cbc:DueDate" mode="PaymentDueDate" >
		<cbc:PaymentDueDate>
			<xsl:value-of select="." />
		</cbc:PaymentDueDate>
	</xsl:template>
	
	<xsl:template match="cbc:PaymentMeansCode" >
		<xsl:variable name="codeVal">
			<xsl:value-of select="." />
		</xsl:variable>
		<cbc:PaymentMeansCode listID="UN/ECE 4461" listAgencyID="6" listName="PaymentMeansCode" listVersionID="D10B" listURI="http://docs.oasis-open.org/ubl/os-UBL-2.1/cl/gc/default/PaymentMeansCode-2.1.gc" listSchemeURI="urn:un:unece:uncefact:codelist:standard:UNECE:PaymentMeansCode:D10B">42</cbc:PaymentMeansCode>
		<!--	<xsl:choose>
				<xsl:when test="normalize-space($codeVal) = 'Transakcijski račun'">42</xsl:when>
				<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
			</xsl:choose>-->
		
		
	
	</xsl:template>	
	
	
	<xsl:template match="cac:Delivery" >
		<cac:Delivery>
			<xsl:apply-templates select="cbc:ActualDeliveryDate" />
			<xsl:apply-templates select="cac:DeliveryLocation" />
			<xsl:apply-templates select="cac:DeliveryParty" />
			<xsl:apply-templates select="cac:Despatch" />
		
		</cac:Delivery>
	
	</xsl:template>
	
	<xsl:template match="cac:Despatch" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:Despatch>
				<xsl:apply-templates select="cbc:ActualDespatchDate" />
				<xsl:apply-templates select="cac:DespatchParty" />
			
			</cac:Despatch>
		</xsl:if>
	</xsl:template>

	<xsl:template match="cac:DespatchParty">
		<xsl:if test="normalize-space(.) != ''" >
			<cac:DespatchParty>
				<xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/>
				
				<xsl:call-template name="DespatchPartyName"/>
				<xsl:apply-templates select="cac:PostalAddress" />
				<xsl:apply-templates select="cac:PhysicalLocation" />
				<!--<xsl:apply-templates select="PartyLegalEntity" mode="CompanyID" />-->
				<xsl:choose>
					<xsl:when test="(normalize-space(cac:PartyLegalEntity/cbc:RegistrationName) != '') and (normalize-space(cac:PartyLegalEntity/cbc:CompanyID) != '')">
						<xsl:apply-templates select="cac:PartyLegalEntity" mode="CompanyID" />
					</xsl:when>
					<xsl:otherwise>
							<xsl:call-template name="AccountingSupplierPartyLegalEntity" />
					</xsl:otherwise>
				</xsl:choose>

				<xsl:apply-templates select="cac:PartyIdentification" />
				
			</cac:DespatchParty>
		</xsl:if>
	
	</xsl:template>
	<xsl:template name="DespatchPartyName">
		<cac:PartyName>
			<cbc:Name><xsl:value-of select="//i:Invoice/cac:Delivery/cac:Despatch/cac:DespatchParty/cac:PhysicalLocation/cbc:ID"/></cbc:Name>
		</cac:PartyName>
	</xsl:template>
	
	
	
	<xsl:template match="cac:PhysicalLocation">
		<xsl:if test="normalize-space(.) != ''" >
			<cac:PhysicalLocation>
				<xsl:apply-templates select="cac:Address" />
			
			</cac:PhysicalLocation>
		</xsl:if>
	
	</xsl:template>
	
		
	<xsl:template match="cac:DeliveryLocation">
		<xsl:if test="normalize-space(.) != ''" >
			<cac:DeliveryLocation>
				<xsl:apply-templates select="cbc:ID" />
				<xsl:apply-templates select="cac:Address" />
				<xsl:apply-templates select="cac:DeliveryParty" />
			
			</cac:DeliveryLocation>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:DeliveryParty" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:DeliveryParty>
				<xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/>
				<xsl:call-template name="PartyName" />
				<xsl:apply-templates select="cac:PostalAddress" />
				<xsl:choose>
					<xsl:when test="(normalize-space(cac:PartyLegalEntity/cbc:RegistrationName) != '') and (normalize-space(cac:PartyLegalEntity/cbc:CompanyID) != '')">
						<xsl:apply-templates select="cac:PartyLegalEntity"/>
					</xsl:when>
					<xsl:otherwise>
							<xsl:call-template name="AccountingCustomerPartyLegalEntity" />
					</xsl:otherwise>
				</xsl:choose>
				
				<xsl:apply-templates select="cac:PartyIdentification" />
	
			</cac:DeliveryParty>
		</xsl:if>
	
	</xsl:template>

	<xsl:template match="cac:PartyLegalEntity">
		<cac:PartyLegalEntity>
			<xsl:apply-templates select="cbc:RegistrationName"/>
			<xsl:apply-templates select="cbc:CompanyID"/>
		</cac:PartyLegalEntity>
		
	</xsl:template>



	<xsl:template match="cac:Address">
		<cac:Address>
			<xsl:apply-templates select="cbc:AddressFormatCode" />
			<xsl:apply-templates select="cbc:StreetName" />
			<xsl:apply-templates select="cbc:AdditionalStreetName" />
			<xsl:apply-templates select="cbc:CityName" />
			<xsl:apply-templates select="cbc:PostalZone" />
			<xsl:apply-templates select="cbc:CountrySubentity" />
			<xsl:apply-templates select="cac:AddressLine" />
			<xsl:apply-templates select="cac:Country" />
		
		</cac:Address>
	
	
	</xsl:template>
	
	
	
	<xsl:template match="cac:TaxRepresentativeParty" >
		<cac:TaxRepresentativeParty>
			<xsl:apply-templates select="cac:PartyName[normalize-space(cbc:Name/text()) != '']" />
			<xsl:apply-templates select="cac:PostalAddress" />
			<!--<xsl:apply-templates select="cac:PartyTaxScheme" mode="TaxRepresentativeParty" />-->
		
		
		</cac:TaxRepresentativeParty>
	
	
	</xsl:template>
	

	
	<xsl:template match="cac:PayeeParty" >
		<cac:PayeeParty>
			<xsl:apply-templates select="cac:PartyName[normalize-space(cbc:Name/text()) != '']" />
			<xsl:apply-templates select="cac:PartyLegalEntity" mode="CompanyID" />
			<xsl:apply-templates select="cac:PartyIdentification"  />
		
		</cac:PayeeParty>
	
	</xsl:template>
	
	<xsl:template match="cac:PartyLegalEntity" mode="CompanyID" >
		<cac:PartyLegalEntity>
			<xsl:apply-templates select="cbc:CompanyID" mode="SchemeID" />
		
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template match="cac:PartyIdentification" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:PartyIdentification>
				<xsl:apply-templates select="cbc:ID" mode="SchemeID" />
			</cac:PartyIdentification>
		
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:AccountingCustomerParty">
		<cac:AccountingCustomerParty>
		
			<xsl:apply-templates select="cac:Party" mode="AccountingCustomerParty" />
			<xsl:apply-templates select="cac:AccountingContact" />
			<xsl:call-template name="AccountingCustomerPartyContact"/>
		
		</cac:AccountingCustomerParty>
	
	</xsl:template>
	
	<xsl:template name="AccountingCustomerPartyContact" >
		<cac:AccountingContact>
			<!--<xsl:apply-templates select="cbc:Name" />-->
			<!--<xsl:apply-templates select="cbc:Telephone" />-->
			<cbc:ElectronicMail>adresar@moj-eracun.hr</cbc:ElectronicMail>
			<!--<xsl:apply-templates select="cbc:Note" />-->
		</cac:AccountingContact>
	</xsl:template>
	
	<xsl:template name="CustomerElectronicMail" >
		<cbc:ElectronicMail>
			<xsl:choose>
				<xsl:when test="cbc:ElectronicMail and ( normalize-space(cbc:ElectronicMail) != '')"><xsl:value-of select="." /></xsl:when>
				<xsl:otherwise>adresar@moj-eracun.hr</xsl:otherwise>
			</xsl:choose>
		
		</cbc:ElectronicMail>
	
	</xsl:template>


	
	<xsl:template match="cac:Party" mode="AccountingCustomerParty" >
		<cac:Party>
			<xsl:choose>
				<xsl:when test="./cac:PartyLegalEntity/cbc:CompanyID = 'HU17781774'">
					<cbc:EndpointID>
						<xsl:choose>
							<xsl:when test="contains(./cac:PartyLegalEntity/cbc:RegistrationName,'PETROCHEMICALS')">6040</xsl:when>
							<xsl:otherwise>09</xsl:otherwise>
						</xsl:choose>
					</cbc:EndpointID>
				</xsl:when>
				<xsl:otherwise><xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/></xsl:otherwise>
			</xsl:choose>
			<xsl:call-template name="PartyName" />
			<xsl:apply-templates select="cac:PostalAddress" />
			<xsl:call-template name="AccountingCustomerPartyLegalEntity" />
			<xsl:copy-of select="cac:PartyIdentification" />
			<xsl:apply-templates select="cac:Contact" />
			<xsl:apply-templates select="cac:Person" />
		
		</cac:Party>
	
	</xsl:template>
	
	<xsl:template name="AccountingCustomerPartyLegalEntity" >
		<cac:PartyLegalEntity>
			<!--<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName" />-->
			<cbc:RegistrationName>
				<!--<xsl:call-template name="GetRegistrationName" />-->
				<xsl:value-of select="$customerRegistrationName" />
			</cbc:RegistrationName>
			<cbc:CompanyID>
				<xsl:value-of select="$customerCompanyId" />
			</cbc:CompanyID>
			
		
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template match="cac:AccountingSupplierParty" >
		<cac:AccountingSupplierParty>
			<xsl:apply-templates select="cbc:CustomerAssignedAccountID" />
			<xsl:apply-templates select="cac:Party" mode="AccountingSupplierParty" />
			<xsl:apply-templates select="cac:AccountingContact" />
		
		</cac:AccountingSupplierParty>
	
	</xsl:template>
	
	<xsl:template match="cac:AccountingContact" >
		<cac:AccountingContact>
			<xsl:apply-templates select="cbc:Name" />
			<xsl:apply-templates select="cbc:Telephone" />
			<xsl:apply-templates select="cbc:ElectronicMail" />
			<xsl:apply-templates select="cbc:Note" />
		</cac:AccountingContact>
	</xsl:template>
	
	
	<xsl:template match="cac:Party" mode="AccountingSupplierParty" >
		<cac:Party>
			<xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/>
			<xsl:call-template name="PartyName" />
			<xsl:apply-templates select="cac:PostalAddress" />
			<xsl:call-template name="AccountingSupplierPartyLegalEntity" />
			<xsl:apply-templates select="cac:Contact" />
			<xsl:apply-templates select="cac:Person" />
		
		</cac:Party>
	
	</xsl:template>
	
	
	<xsl:template match="cac:Person" >
		<cac:Person>
			<xsl:apply-templates select="cbc:FirstName" />
			<xsl:apply-templates select="cbc:FamilyName" />
			<xsl:apply-templates select="cbc:JobTitle" />
			<xsl:apply-templates select="cbc:OrganizationDepartment" />
		</cac:Person>
	
	
	</xsl:template>
	
	<xsl:template match="cac:Contact">
		<cac:Contact>
			<xsl:apply-templates select="cbc:Telephone" />
		</cac:Contact>
	
	</xsl:template>
		
	<xsl:template name="AccountingSupplierPartyLegalEntity" >
		<cac:PartyLegalEntity>
			<!--<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName" />-->
			<!--<xsl:apply-templates select="cbc:CompanyID" mode="SchemeID" />-->
			<cbc:RegistrationName>
				<!--<xsl:call-template name="GetRegistrationName" />-->
				<xsl:value-of select="$supplierRegistrationName" />
			</cbc:RegistrationName>
					
			<cbc:CompanyID>
				<xsl:value-of select="$supplierCompanyId" />
			</cbc:CompanyID>

		
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template name="GetPartyName" >

		<xsl:choose>
			<xsl:when test="cac:PartyName/cbc:Name and (normalize-space(cac:PartyName/cbc:Name) != '')">
				<xsl:value-of select="normalize-space(cac:PartyName/cbc:Name)" />
			</xsl:when>
			<xsl:when test="cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(cac:PartyLegalEntity/cbc:RegistrationName) != '')">
				<xsl:value-of select="normalize-space(cac:PartyLegalEntity/cbc:RegistrationName)" />
			</xsl:when>
		
		</xsl:choose>
	
	</xsl:template>
	
<!--	<xsl:template name="GetRegistrationName" >

		<xsl:choose>
			<xsl:when test="cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(cac:PartyLegalEntity/cbc:RegistrationName) != '')">
				<xsl:value-of select="normalize-space(cac:PartyLegalEntity/cbc:RegistrationName)" />
			</xsl:when>
			<xsl:when test="cac:PartyName/cbc:Name and (normalize-space(cac:PartyName/cbc:Name) != '')">
				<xsl:value-of select="normalize-space(cac:PartyName/cbc:Name)" />
			</xsl:when>
		
		</xsl:choose>
	
	</xsl:template>-->
	
	
	<xsl:template name="PartyName" >
		<xsl:variable name="partyName">
			<xsl:call-template name="GetPartyName" />
		</xsl:variable>
		<xsl:if test="normalize-space($partyName) != ''" >
			<cac:PartyName>
				<cbc:Name><xsl:value-of select="normalize-space($partyName)" /></cbc:Name>
			</cac:PartyName>
		
		</xsl:if>
	
	
	</xsl:template>
	
	
	<xsl:template name="PartyTaxScheme" >
		<cac:PartyTaxScheme>
<!--			<xsl:if test="$isOutsideVAT = 'false'">
				<xsl:apply-templates select="cac:PartyLegalEntity/cbc:CompanyID" mode="PartyTaxID"/>
			</xsl:if>
-->			<cac:TaxScheme>
				<cbc:ID>VAT</cbc:ID>
			</cac:TaxScheme>
		
		</cac:PartyTaxScheme>
	
	</xsl:template>
	
	<xsl:template match="cac:PostalAddress" >
		<cac:PostalAddress>
			<xsl:apply-templates select="cbc:AddressFormatCode" />
			<xsl:apply-templates select="cbc:StreetName" />
			<xsl:apply-templates select="cbc:AdditionalStreetName" />
			<xsl:apply-templates select="cbc:CityName" />
			<xsl:apply-templates select="cbc:PostalZone" />
			<xsl:apply-templates select="cbc:CountrySubentity" />
			<xsl:apply-templates select="cac:AddressLine" />
			<xsl:apply-templates select="cac:Country" />
			
		</cac:PostalAddress>
	
	</xsl:template>
	
	<xsl:template match="cac:Country" >
		<cac:Country>
			<xsl:apply-templates select="cbc:IdentificationCode" />
			<xsl:apply-templates select="cbc:Name" />
		
		</cac:Country>
	
	</xsl:template>
	
	<xsl:template match="cbc:IdentificationCode" >
		<cbc:IdentificationCode listID="ISO3166-1" listAgencyID="6" listAgencyName="United Nations Economic Commission for Europe" listName="Country" listVersionID="0.3" name="String" listURI="http://docs.oasis-open.org/ubl/os-ubl-2.0/cl/gc/default/CountryIdentificationCode-2.0.gc" listSchemeURI="urn:oasis:names:specification:ubl:codelist:gc:CountryIdentificationCode-2.0">
			<xsl:value-of select="." />
		</cbc:IdentificationCode>
	</xsl:template>
	
	<xsl:template match="cac:AddressLine">
		<xsl:if test="normalize-space(.) != ''">
			<cac:AddressLine>
				<xsl:apply-templates select="cbc:Line" />
			</cac:AddressLine>
		</xsl:if>
	</xsl:template>
	

		
	<xsl:template match="cac:PartyName" >
		<cac:PartyName>
			<xsl:choose>
				<xsl:when test="cbc:Name and (normalize-space(cbc:Name) != '')">
					<cbc:Name><xsl:value-of select="cbc:Name" /></cbc:Name>
				</xsl:when>
				<xsl:when test="../cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(../cac:PartyLegalEntity/cbc:RegistrationName) != '')">
					<cbc:Name><xsl:value-of select="../cac:PartyLegalEntity/cbc:RegistrationName" /></cbc:Name>
				
				</xsl:when>
			</xsl:choose>
		</cac:PartyName>
	
	</xsl:template>
	
	
	
	<xsl:template match="cac:AdditionalDocumentReference">
			<cac:AdditionalDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="FiscalAdditionalDocumentReference" />
				<xsl:apply-templates select="cbc:IssueDate" />	
				<!--<xsl:apply-templates select="cbc:DocumentTypeCode" />-->
				<xsl:apply-templates select="cbc:DocumentType" />
			</cac:AdditionalDocumentReference>
		

	</xsl:template>
	
	<xsl:template match="cac:AdditionalDocumentReference" mode="SapTypeID">
		<cac:AdditionalDocumentReference>
			<cbc:ID><xsl:value-of select="$SAPTypeID"/></cbc:ID>
			<cbc:DocumentType>SAPTypeID</cbc:DocumentType>
		</cac:AdditionalDocumentReference>
		
		
	</xsl:template>
	
	
	<xsl:template match="cbc:ID" mode="FiscalAdditionalDocumentReference">
		<cbc:ID>
			<xsl:choose>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '15538072333'">
					<xsl:choose>
						<xsl:when test="not(contains(.,'RIZ'))">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="not(contains(../../cbc:ID,'RIZ'))">
									<xsl:value-of select="../../cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID = '99172175603'">
					<xsl:choose>
						<xsl:when test="not(contains(.,'STSI'))">
							<xsl:value-of select="."/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:choose>
								<xsl:when test="not(contains(../../cbc:ID,'STSI'))">
									<xsl:value-of select="../../cbc:ID"/>
								</xsl:when>	
								<xsl:otherwise>
									<xsl:value-of select="."/>
								</xsl:otherwise>
							</xsl:choose>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="."/>
				</xsl:otherwise>
			</xsl:choose>
		</cbc:ID>
	</xsl:template>
	
	<xsl:template match="cac:ContractDocumentReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:ContractDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />		
			</cac:ContractDocumentReference>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:OriginatorDocumentReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:OriginatorDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />		
			</cac:OriginatorDocumentReference>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:ReceiptDocumentReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:ReceiptDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />		
			</cac:ReceiptDocumentReference>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:DespatchDocumentReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:DespatchDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />		
				<xsl:choose>
					<xsl:when test="cbc:DocumentType and (normalize-space(cbc:DocumentType) != '')">
						<xsl:apply-templates select="cbc:DocumentType" />	
					</xsl:when>
					<xsl:otherwise>
						<cbc:DocumentType>351</cbc:DocumentType>
					</xsl:otherwise>
				</xsl:choose>
			</cac:DespatchDocumentReference>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:BillingReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:BillingReference>
				<xsl:apply-templates select="cac:InvoiceDocumentReference" />
			
			</cac:BillingReference>	
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:InvoiceDocumentReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:InvoiceDocumentReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />
			</cac:InvoiceDocumentReference>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cac:OrderReference" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:OrderReference>
				<xsl:apply-templates select="cbc:ID" mode="ID" />
				<xsl:apply-templates select="cbc:IssueDate" />		
			</cac:OrderReference>
		</xsl:if>
	
	</xsl:template>
	

	
	<xsl:template match="cac:InvoicePeriod" >
		<xsl:if test="normalize-space(.) != ''" >
			<cac:InvoicePeriod>
				<xsl:apply-templates select="cbc:StartDate" />
				<xsl:apply-templates select="cbc:EndDate" />
				<!--<xsl:apply-templates select="cbc:DescriptionCode" />-->
			
			</cac:InvoicePeriod>
		</xsl:if>
	
	</xsl:template>
	
	<xsl:template match="cbc:CopyIndicator">
		<cbc:CopyIndicator>
			<xsl:value-of select="translate(., 'FALSETRU', 'falsetru')" />
		</cbc:CopyIndicator>
	
	</xsl:template>
	
	<xsl:template match="cbc:DocumentCurrencyCode">
		<cbc:DocumentCurrencyCode listID="ISO 4217 Alpha" listAgencyID="5" listSchemeURI="http://docs.oasis-open.org/ubl/os-UBL-2.1/cl/gc/default/CurrencyCode-2.1.gc">
			<xsl:value-of select="." />
		</cbc:DocumentCurrencyCode>
	</xsl:template>
	
	<xsl:template match="cbc:InvoiceTypeCode">
		<cbc:InvoiceTypeCode listID="UN/ECE 1001" listAgencyID="6" listURI="http://www.unece.org/trade/untdid/d00a/tred/tred1001.htm">
			<xsl:value-of select="." />
		</cbc:InvoiceTypeCode>
	
	</xsl:template>
	
	<xsl:template match="ihi:IssuePlace" mode="UBLExtension" >
          <ext:UBLExtension>
            <cbc:ID>HRINVOICE1</cbc:ID>
            <cbc:Name>InvoiceIssuePlaceData</cbc:Name>
            <ext:ExtensionAgencyID>MINGORP</ext:ExtensionAgencyID>
            <ext:ExtensionAgencyName>MINGORP</ext:ExtensionAgencyName>
            <ext:ExtensionAgencyURI>MINGORP</ext:ExtensionAgencyURI>
            <ext:ExtensionURI>urn:invoice:hr:issueplace</ext:ExtensionURI>
            <ext:ExtensionReasonCode>MandatoryField</ext:ExtensionReasonCode>
            <ext:ExtensionReason>Mjesto izdavanja računa prema Pravilniku o PDV-u</ext:ExtensionReason>
            <ext:ExtensionContent>
              <ext:InvoiceIssuePlace>
				  <xsl:value-of select="." />
              </ext:InvoiceIssuePlace>
            </ext:ExtensionContent>
          </ext:UBLExtension>

	</xsl:template>
	
	<xsl:template match="cbc:CompanyLegalForm" mode="UBLExtension">
		<ext:UBLExtension>
            <cbc:ID>HRINVOICE1</cbc:ID>
            <cbc:Name>InvoiceIssuerData</cbc:Name>
            <ext:ExtensionAgencyID>FINA</ext:ExtensionAgencyID>
            <ext:ExtensionAgencyName>FINA</ext:ExtensionAgencyName>
            <ext:ExtensionAgencyURI>FINA</ext:ExtensionAgencyURI>
            <ext:ExtensionURI>urn:invoice:hr:issuer</ext:ExtensionURI>
            <ext:ExtensionReasonCode>MandatoryField</ext:ExtensionReasonCode>
            <ext:ExtensionReason>Podaci o izdavatelju prema Zakonu o trgovačkim društvima</ext:ExtensionReason>
            <ext:ExtensionContent>
				<ext:InvoiceIssuer>
					<xsl:value-of select="." />
				</ext:InvoiceIssuer>
			</ext:ExtensionContent>
		</ext:UBLExtension>
		
	</xsl:template>
	

	
	<xsl:template name="HROutgoingInvoiceHeader" >

		<n:SupplierInvoiceID>
			<xsl:value-of select="string(/i:Invoice/cbc:ID)"/>
		</n:SupplierInvoiceID>
		<n:BuyerID>
			<!--<xsl:value-of select="string(/i:Invoice/cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID)"/>-->
			<xsl:value-of select="$customerCompanyId" />
		</n:BuyerID>
		
	</xsl:template>

	<xsl:template name="HRInvoiceHeader">
	
			<n:Header>
				<n:SupplierID>
					<!--<xsl:value-of select="/i:Invoice/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID"/>-->
					<xsl:value-of select="$supplierCompanyId" />
				</n:SupplierID>
				
				<n:InvoiceType>
					<xsl:value-of select="1"/>
				</n:InvoiceType>
			</n:Header>

	</xsl:template>		

	
	<!-- GENERIC ELEMENTS-->
	
	<xsl:template match="cbc:Note">
		<!--<xsl:variable name="vrijeme1" select="substring-after(., 'Vrijeme izdavanja:')" />
		<xsl:variable name="vrijeme2" select="substring-before($vrijeme1, '#AAI#')" />
		<xsl:if test="normalize-space($vrijeme2) = ''">
			<cbc:Note><xsl:value-of select="." /></cbc:Note>
		</xsl:if>-->
		<xsl:choose>
			<xsl:when test="normalize-space(substring-before(., '#AAI#')) != ''" />
			<xsl:when test="normalize-space(substring-before(., '#Vrijeme izdavanja')) != ''" />
			<xsl:when test="normalize-space(substring-before(., '#Oznaka operatera')) != ''" />
			<xsl:when test="normalize-space(substring-before(., '#Odgovorna osoba')) != ''" />
			<xsl:when test="normalize-space(substring-after(., 'Vrijeme izdavanja:')) != ''" />

			<xsl:otherwise><cbc:Note><xsl:value-of select="." /></cbc:Note></xsl:otherwise>
		</xsl:choose>

	</xsl:template>
		
	<xsl:template match="cbc:Note" mode="IssueTime">
		<xsl:if test="normalize-space($issueTime) != ''">
			<cbc:IssueTime><xsl:value-of select="$issueTime" /></cbc:IssueTime>

		</xsl:if>
	
	</xsl:template>

	
	<xsl:template match="cbc:Amount | cbc:BaseAmount | cbc:TaxAmount | cbc:TaxableAmount
		| cbc:LineExtensionAmount | cbc:TaxExclusiveAmount | cbc:TaxInclusiveAmount
		| cbc:AllowanceTotalAmount | cbc:ChargeTotalAmount | cbc:PrepaidAmount
		| cbc:PayableRoundingAmount | cbc:PayableAmount " >
		<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
			<xsl:attribute name="currencyID" namespace="">
				<xsl:choose>
					<xsl:when test="normalize-space(@currencyID) = ''">HRK</xsl:when>
					<xsl:otherwise><xsl:value-of select="@currencyID" /></xsl:otherwise>
				</xsl:choose>
				
			</xsl:attribute>
			<xsl:choose>
				<xsl:when test="number(.) = 0">0.00</xsl:when>
				<xsl:when test="string(number(.))='NaN'">0.00</xsl:when>
				<xsl:otherwise><xsl:value-of select="format-number(number(.), '#0.00')" /></xsl:otherwise>
			</xsl:choose>

			<!--<xsl:value-of select="format-number(number(.), '#.00')" />-->
		</xsl:element>
	
	</xsl:template>
	
	<xsl:template match="cbc:PriceAmount" >
		<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
			<xsl:attribute name="currencyID" namespace="">
				<xsl:value-of select="@currencyID" />
			</xsl:attribute>
			<xsl:choose>
				<xsl:when test="number(.) = 0">0.00</xsl:when>
				<xsl:when test="string(number(.))='NaN'">0.00</xsl:when>
				<xsl:otherwise>
					<xsl:variable name="priceAmount">
						<xsl:value-of select="format-number(number(.), '#0.00')" />
					</xsl:variable>
					<xsl:choose>
						<xsl:when test="string-length(string(.)) &gt; string-length(string($priceAmount))">
							<xsl:value-of select="." />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$priceAmount" />
						</xsl:otherwise>
					</xsl:choose>
				
				</xsl:otherwise>
			</xsl:choose>
			
		</xsl:element>
	
	</xsl:template>
	

	
	<xsl:template match="cbc:MultiplierFactorNumeric">
		<cbc:MultiplierFactorNumeric>
			<xsl:choose>
				<xsl:when test="string(number(.)) != 'NaN'">
					<xsl:value-of select="number(.)" />
				</xsl:when>
				<xsl:otherwise>0</xsl:otherwise>
			</xsl:choose>

		</cbc:MultiplierFactorNumeric>
	
	</xsl:template>

	<xsl:template match="cbc:Percent">
		<cbc:Percent>
			<xsl:value-of select="number(.)" />
		</cbc:Percent>
	
	</xsl:template>
	
	<xsl:template match="cbc:CompanyID" mode="PartyIdentification">
		<cac:PartyIdentification>
			<cbc:ID>
				<xsl:value-of select="concat('9934:', .)"/>
			</cbc:ID>
		
		</cac:PartyIdentification>
	
	</xsl:template>
	
	<xsl:template match="cbc:CompanyID" mode="PartyTaxID">
		<cbc:CompanyID>
			<xsl:value-of select="concat('HR', .)"/>
		</cbc:CompanyID>
	
	</xsl:template>

	
	<xsl:template match="cbc:CompanyID" mode="EndpointID" >
		<cbc:EndpointID>
			<xsl:attribute name="schemeID" namespace="">9934</xsl:attribute>
			<xsl:value-of select="." />
		
		</cbc:EndpointID>
	
	</xsl:template>
	
	<xsl:template match="cbc:EndpointID" mode="CompanyID">
	
		<cbc:CompanyID>
			<xsl:value-of select="." />
		</cbc:CompanyID>
	</xsl:template>
	
	<xsl:template match="cbc:ID" mode="PartyID2CompanyID">
		<xsl:variable name="id1"><xsl:value-of select="substring-after(., ':')" /></xsl:variable>
		<xsl:variable name="id2"><xsl:value-of select="substring-before($id1, '::HR99')" /></xsl:variable>
	
		<cbc:CompanyID>
			<xsl:choose>
				<xsl:when test="normalize-space($id2) != ''"><xsl:value-of select="$id2" /></xsl:when>
				<xsl:when test="normalize-space($id1) != ''"><xsl:value-of select="$id1" /></xsl:when>
				<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
			</xsl:choose>
		</cbc:CompanyID>
	</xsl:template>

	<xsl:template match="cbc:CompanyID" mode="TaxID2CompanyID">
	
		<cbc:CompanyID>
			<xsl:value-of select="substring-after(., 'HR')" />
		</cbc:CompanyID>
	</xsl:template>

	
	<xsl:template match="cbc:EndpointID" mode="SchemeID">
		<cbc:EndpointID>
			<xsl:apply-templates select="@schemeID" />
			<xsl:value-of select="." />
		</cbc:EndpointID>
	</xsl:template>

	<xsl:template match="cbc:ID | cbc:CompanyID " mode="SchemeID" >
		<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
			<xsl:apply-templates select="@schemeID" />

			<xsl:value-of select="." />
		</xsl:element>
	</xsl:template>
	
	<xsl:template match="@schemeID" >
		<xsl:attribute name="schemeID" namespace="">
			<xsl:value-of select="." />
		</xsl:attribute>
	
	</xsl:template>
	
	<xsl:template match="cbc:ID" mode="ID">
		<cbc:ID><xsl:value-of select="." /></cbc:ID>
	</xsl:template>
	
	<xsl:template match="cbc:DocumentType" >
		<cbc:DocumentType><xsl:value-of select="." /></cbc:DocumentType>
	
	</xsl:template>


	<xsl:template match="cbc:*" >
<!--		<xsl:copy>
			<xsl:value-of select="." />
		</xsl:copy>-->
		<xsl:if test="normalize-space(.) != ''" >
			<xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
				<xsl:value-of select="." />
			</xsl:element>
		</xsl:if>
	</xsl:template>
	

</xsl:stylesheet>
