<?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 or Elektronički računi d.o.o., 
 -->
 <!-- V 2019-10-21-v15 
*** Maknute namespace deklaracije za i: a: ns1:
-->
<!-- V 2019-09-24-v14
*** PartyIdentification se kreira samo ako Party ima podjedinice - inače ne
-->
 <!-- v2019-09-23-V13
*** Dodana logika da ispravno hendla dupli PartyName i PartyLegalEntity

*** Promijenjen redosljed traženja OIBa: sada prvo gleda EndpointID ako sadrži oib (shema 9934 - jer tu možemo biti sigurni da je OIB, a u PartyIdentification ne možemo)

-->
 <!-- V2019-09-13-v11
*** Dodana kontrola da CompanyID mora biti 11 znakova da se uzme kao OIB

-->
 <!-- V2019-09-09-v10
*** ProfileID je UVIJEK MojEracunInvoice

-->
 <!-- V2019-09-06-v9
*** Dodaje u komentar identifikator transformacije

*** logika za pronalaženje CompanyID Suppiera i Customera iz V7 centralizirana u varijablama
- $supplierCompanyId
- $customerCompanyId
.. i primijenjena u headerima, attachmentima i u dokumentu
-->

 <!-- V2019-08-22-v8
*** Dodano da izvlači PartyName ako ga nema iz LegalMonetaryTotal/cbc:CompanyName 

*** Vrijeme izdavanja: parsira i samo Note koji ima "Vrijeme izdavanja:"

*** AllowanceTotalAmount - uvijek stavlja element s vrijednosti 0.00 ako je prazan

-->
<!-- V2019-08-14-v7
*** Dodano da uvijek popunjava PartyLegalEntity/cbc:CompanyID
- Prvo sa CompanyID
- Pa sa EndpointID ako je shema 9934
- Pa sa PartyIdentification/cbc:ID ako počinje sa 9934:
- Pa sa PartyTaxScheme/cbc:CompanyID ako počinje sa HR

--> 
 
 <!-- V 2019-08-12-v6
*** Ispravljen bug da zaokružuje cbc:PriceAmount na dvije decimela
- Ako ima manje od dvije decimale, imati će dvije decimale
- Ako ima više, imati će koliko ima

-->
 <!-- V 2019-07-26-v5
***cbc:TaxCategory/cbc:Percent se uvijek kreira
- ako je kategorija O stavlja se default 0.00

*** V 2020-11 
Promijenjeno mapiranje AdditionalItemProperty:
- ako je cbc:Name AdditionalItemIdentification - ide u cac:AdditionalItemIdentification
- ako je cbc:Name ManufacturersItemIentification - ide u cac:ManufacturersItemIentification
- Ne generira se AdditionalItemProperty u gornja dva slučaja

V 2021-01-11
***Vrijednost PaymentID-a se prebacuje u InstructionID
- ako nema HR u modelu plaćanja, kreiraj ga


V 2021-01-27
U DeliveryParty-ju dodana provjera ako postoji PartyLegalEntity
-ako ne, uzmi podatke iz AccountingCustomerParty/Party/PartyLegalEntity

V 2021-01-27
U DeliveryParty-ju dodana provjera ako postoji PartyLegalEntity
-ako ne, uzmi podatke iz AccountingCustomerParty/Party/PartyLegalEntity


-->
<xsl:stylesheet version="1.0" 

xmlns:c="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2"
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:exthr ="urn:invoice:hr:schema:xsd:CommonExtensionComponents-1"
 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" 
 exclude-result-prefixes="ccts-cct ds n0 n2 qdt2 sac sbc udt2 xades xs xsi xsl i ns1 a n c" 
 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="responsiblePerson">
		
		<xsl:for-each select="/c:CreditNote/cbc:Note">
			<xsl:variable name="person1" select="substring-before(., '#Odgovorna osoba')" />
			<xsl:variable name="person2" select="substring-after(., 'Odgovorna osoba:')" />
			<xsl:variable name="person3" select="substring-after(., 'Odgovorna osoba#')" />
			<xsl:variable name="person4" select="substring-after(., 'Responsible person:')" />
			<xsl:choose>
				<xsl:when test="normalize-space($person1) != ''">
					<xsl:value-of select="normalize-space($person1)" />
				</xsl:when>
				<xsl:when test="normalize-space($person2) != ''">
					<xsl:value-of select="normalize-space($person2)" />
				</xsl:when>						
				<xsl:when test="normalize-space($person3) != ''">
					<xsl:value-of select="normalize-space($person3)" />
				</xsl:when>
				<xsl:when test="normalize-space($person4) != ''">
					<xsl:value-of select="normalize-space($person4)" />
				</xsl:when>
			</xsl:choose>
		</xsl:for-each>
		
	</xsl:variable>
	
	<xsl:variable name="operator">
		
		<xsl:for-each select="/c:CreditNote/cbc:Note">
			<xsl:variable name="operator1" select="substring-before(., '#Oznaka operatera')" />
			<xsl:variable name="operator2" select="substring-after(., 'Oznaka operatera:')" />
			<xsl:variable name="operator3" select="substring-after(., 'Operator:')" />
			<xsl:variable name="operator4" select="substring-after(., 'Oznaka operatera#')" />
			<xsl:choose>
				<xsl:when test="normalize-space($operator1) != ''">
					<xsl:value-of select="normalize-space($operator1)" />
				</xsl:when>
				<xsl:when test="normalize-space($operator2) != ''">
					<xsl:value-of select="normalize-space($operator2)" />
				</xsl:when>						
				<xsl:when test="normalize-space($operator3) != ''">
					<xsl:value-of select="normalize-space($operator3)" />
				</xsl:when>
				<xsl:when test="normalize-space($operator4) != ''">
					<xsl:value-of select="normalize-space($operator4)" />
				</xsl:when>
			</xsl:choose>
		</xsl:for-each>
		
	</xsl:variable>
	
	<xsl:variable name="issueTime">
		<xsl:choose>
			<xsl:when test="/c:CreditNote/cbc:IssueTime">
					<xsl:value-of select="/c:CreditNote/cbc:IssueTime" />
			</xsl:when>
			<xsl:when test="/c:CreditNote/cbc:Note" >
				<xsl:for-each select="/c:CreditNote/cbc:Note">
					<xsl:variable name="vrijeme1" select="substring-after(., 'Vrijeme izdavanja:')" />
					<xsl:variable name="vrijeme2" select="substring-before($vrijeme1, '#AAI#')" />
					<xsl:variable name="vrijeme3" select="substring-before(., '#Vrijeme izdavanja')" />
					<xsl:choose>
						<xsl:when test="normalize-space($vrijeme3) != ''">
							<xsl:value-of select="normalize-space($vrijeme3)" />
						</xsl:when>						
						<xsl:when test="normalize-space($vrijeme2) != ''">
							<xsl:value-of select="normalize-space($vrijeme2)" />
						</xsl:when>
						<xsl:when test="normalize-space($vrijeme1) != ''">
							<xsl:value-of select="normalize-space($vrijeme1)" />
						</xsl:when>
		<!--				<xsl:when test="normalize-space(substring-before(., '#Vrijeme izdavanja')) != ''">
							<xsl:value-of select="normalize-space(substring-before(., '#Vrijeme izdavanja'))" /
						</xsl:when>
		>-->			
					</xsl:choose>
				</xsl:for-each>
			</xsl:when>
		</xsl:choose>
	</xsl:variable>
	
	<xsl:variable name="supplierCompanyId">
		<xsl:choose>
			<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cbc:EndpointID[@schemeID='9934']">
				<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cbc:EndpointID" mode="CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID and (string-length(normalize-space(//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID)) = 11)">
				<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID" mode="SchemeID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID[starts-with(text(), '9934:')]">
				<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cac:PartyIdentification/cbc:ID" mode="PartyID2CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID[starts-with(text(), 'HR')]">
				<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID" mode="TaxID2CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cbc:EndpointID">
				<xsl:apply-templates select="//cac:AccountingSupplierParty/cac:Party/cbc:EndpointID" mode="CompanyID" />
			</xsl:when>

		</xsl:choose>

	</xsl:variable>
	
	<xsl:variable name="customerCompanyId">
		<xsl:choose>
			<xsl:when test="//cac:AccountingCustomerParty/cac:Party/cbc:EndpointID[@schemeID='9934']">
				<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cbc:EndpointID" mode="CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID and (string-length(normalize-space(//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID)) = 11)">
				<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID" mode="SchemeID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID[starts-with(text(), '9934:')]">
				<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cac:PartyIdentification/cbc:ID" mode="PartyID2CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID[starts-with(text(), 'HR')]">
				<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cac:PartyTaxScheme/cbc:CompanyID" mode="TaxID2CompanyID" />
			</xsl:when>
			<xsl:when test="//cac:AccountingCustomerParty/cac:Party/cbc:EndpointID">
				<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cbc:EndpointID" mode="CompanyID" />
			</xsl:when>

		</xsl:choose>

	</xsl:variable>

	
	<xsl:template match="/">
					<xsl:apply-templates select="/c:CreditNote" />
	</xsl:template>
	
	<xsl:template match="cac:AdditionalDocumentReference" mode="Attachment">
		<AttachedDocument xmlns="urn:oasis:names:specification:ubl:schema:xsd:AttachedDocument-2">
			<cbc:ID>
				<xsl:value-of select="cbc:ID" />
			</cbc:ID>
			<cbc:IssueDate>
				<xsl:value-of select="/c:CreditNote/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="/c:CreditNote/cbc:ID" /></cbc:ParentDocumentID>
			<cac:SenderParty>
				<xsl:apply-templates select="/c:CreditNote/cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity" mode="SupplierAttachment" />
			</cac:SenderParty>
			<cac:ReceiverParty>
				<xsl:apply-templates select="/c:CreditNote/cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity" mode="CustomerAttachment" />
			</cac:ReceiverParty>
			
			<xsl:apply-templates select="cac:Attachment" 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="c:CreditNote">
		
		<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-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:exthr="urn:invoice:hr:schema:xsd:CommonExtensionComponents-1"
		>
		
			
			<ext:UBLExtensions>
				<xsl:call-template name="UBLExtensionInvoiceIssuer"/>
				<xsl:call-template name="UBLExtensionIssuePlace"/>
			</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="ID" />
			<cbc:CopyIndicator>false</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:Note" />
			<xsl:apply-templates select="cbc:DocumentCurrencyCode" />
			<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" mode="ID" />
			
			<xsl:apply-templates select="//ns0:AttachedDocumentEnvelope/ns1:AttachedDocument" mode="Attachment" />-->
			
			<xsl:apply-templates select="cac:ProjectReference" />
			<xsl:apply-templates select="cac:OrderReference/cbc:SalesOrderID"/>
			<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:CreditNoteLine" />
		
		</CreditNote>
	
	</xsl:template>
	
	<xsl:template name="UBLExtensionIssuePlace">		
		<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>
				<exthr:InvoiceIssuePlace>
					<xsl:value-of select="//cac:AccountingSupplierParty/cac:Party/cac:PostalAddress/cbc:CityName" />
				</exthr:InvoiceIssuePlace>
			</ext:ExtensionContent>
		</ext:UBLExtension>
		
	</xsl:template>
	
	<xsl:template name="UBLExtensionInvoiceIssuer">
		<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>
				<exthr:InvoiceIssuer>
					<xsl:choose>
						<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm"><xsl:value-of select="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyLegalForm"/></xsl:when>
						<xsl:when test="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName"><xsl:value-of select="//cac:AccountingSupplierParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName"/></xsl:when>
						<xsl:otherwise><xsl:value-of select="//cac:AccountingSupplierParty/cac:Party/cac:PartyName/cbc:Name"/></xsl:otherwise>
					</xsl:choose>
				</exthr:InvoiceIssuer>
			</ext:ExtensionContent>
		</ext:UBLExtension>
		
	</xsl:template>
	
	<xsl:template match="cac:CreditNoteLine">
		<cac:CreditNoteLine>
			<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:DocumentReference" mode="InvoiceLine"/>
			<xsl:apply-templates select="cac:DespatchLineReference" mode="InvoiceLine"/>
			
			<!--<xsl:apply-templates select="cac:Item/cac:TaxCategory" mode="AllowanceChargeLine" />
			-->
			<xsl:variable name="taxCategoryNode">
				<xsl:apply-templates select="cac:Item/cac:ClassifiedTaxCategory" 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:Item/cac:ClassifiedTaxCategory/cbc:Percent)" /></xsl:variable>
			<xsl:call-template name="HRTaxTotal">
				<xsl:with-param name="currencyID" select="$currencyID" />
				<xsl:with-param name="taxableAmount" select="$taxableAmount"/>
				<xsl:with-param name="percent" select="$percent"/>		
				<xsl:with-param name="taxCategoryNode" select="$taxCategoryNode" />
			</xsl:call-template>
			<xsl:apply-templates select="cac:AllowanceCharge" mode="InvoiceLine" />
			<xsl:apply-templates select="cac:Item" mode="InvoiceLine" />
			<xsl:apply-templates select="cac:Price" mode="InvoiceLine" />
			

		</cac:CreditNoteLine>
		
	</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:Name" />
			<xsl:apply-templates select="cac:BuyersItemIdentification" />
			<xsl:apply-templates select="cac:SellersItemIdentification" />
			<xsl:apply-templates select="cac:AdditionalItemProperty[cbc:Name/text() = 'ManufacturersItemIdentification']" mode="ManufacturersItemIdentification" />
			<xsl:apply-templates select="cac:StandardItemIdentification" />
			<xsl:apply-templates select="cac:AdditionalItemIdentification" />
			<xsl:apply-templates select="cac:AdditionalItemProperty[cbc:Name/text() = 'AdditionalItemIdentification']" mode="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">
		<cac:AdditionalItemProperty>
			<xsl:apply-templates select="cbc:Name" />
			<xsl:apply-templates select="cbc:Value" />
		
		</cac:AdditionalItemProperty>
	
	</xsl:template>
	
	<xsl:template match="cac:AdditionalItemProperty" mode="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="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:Item/cac:ClassifiedTaxCategory" 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="$currencyID" />
				<xsl:with-param name="taxableAmount" select="$taxableAmount"/>
				<xsl:with-param name="percent" select="$percent"/>		
				<xsl:with-param name="taxCategoryNode" select="$taxCategoryNode" />
			</xsl:call-template>
		</cac:AllowanceCharge>
			

	
	</xsl:template>
	
	<xsl:template match="cac:ClassifiedTaxCategory" mode="AllowanceChargeLine">
		<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="/c:CreditNote/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:DocumentReference>
				<cbc:ID schemeID="AAK">
					<xsl:value-of select="cbc:LineID" />
				</cbc:ID>
			</cac:DocumentReference>
		</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">
		<cac:InvoicePeriod>
			<xsl:apply-templates select="cbc:StartDate" />
			<xsl:apply-templates select="cbc:EndDate" />
		
		</cac:InvoicePeriod>
	
	</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" >
		<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">
		<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:apply-templates select="cac:TaxCategory" mode="AllowanceCharge" />
			
		</cac:AllowanceCharge>
	
	</xsl:template>
	
	<xsl:template name="HRTaxTotal">
		<xsl:param name="currencyID" select="'HRK'" />
		<xsl:param name="taxableAmount" select="0"/>
		<xsl:param name="percent" select="0"/>
		<xsl:param name="taxCategoryNode" />
			<!--<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, '#.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:value-of select="$taxableAmount" />					 
					 </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:copy-of select="$taxCategoryNode" />
				 </cac:TaxSubtotal>
			</cac:TaxTotal>
	
	</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:value-of select="$taxCategoryID" />
		</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: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">
		<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="/c:CreditNote/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="/c:CreditNote/cbc:DueDate" mode="PaymentDueDate" />
			<cbc:PaymentChannelCode listAgencyName="CEN/BII">IBAN</cbc:PaymentChannelCode>
			<xsl:apply-templates select="cbc:PaymentID" mode="InstructionID" />
			<xsl:apply-templates select="cbc:InstructionNote" />
			<xsl:apply-templates select="cac:CardAccount" />
			<xsl:apply-templates select="cac:PayeeFinancialAccount" mode="PaymentMeans" />
			<xsl:apply-templates select="cac:PaymentMandate" />
			
		
		</cac:PaymentMeans>
	
	</xsl:template>
	
	<xsl:template match="cac:PaymentMandate" >
		<cac:PaymentMandate>
			<xsl:apply-templates select="cbc:ID" />
			<xsl:apply-templates select="cac:PayeeFinancialAccount" mode="PaymentMandate" />
		
		</cac:PaymentMandate>	
	
	</xsl:template>
	
	<xsl:template match="cac:PayeeFinancialAccount" mode="PaymentMandate" >
		<cac:PayeeFinancialAccount>
			<xsl:apply-templates select="cbc:ID" />
			<xsl:apply-templates select="/c:CreditNote/cbc:DocumentCurrencyCode" mode="CurrencyCode" />

		</cac:PayeeFinancialAccount>
	
	</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="/c:CreditNote/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="cbc:ID" />
			
			</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 match="cbc:PaymentID" mode="InstructionID" >
		<cbc:InstructionID>
			<xsl:choose>
				<xsl:when test="contains(substring-before(.,' '),'HR')">
					<xsl:value-of select="."/>
				</xsl:when>
				<xsl:otherwise><xsl:value-of select="concat('HR',.)"/></xsl:otherwise>
			</xsl:choose>
		</cbc:InstructionID>
		
	</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">
			<xsl:choose>
				<xsl:when test="normalize-space($codeVal) = '30'">42</xsl:when>
				<xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
			</xsl:choose>
		
		</cbc:PaymentMeansCode>
	
	</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" />
		
		</cac:Delivery>
	
	</xsl:template>

	
	
	<xsl:template match="cac:DeliveryParty" >
		<cac:DeliveryParty>
			<xsl:apply-templates select="cbc:WebsiteURI"/>
			<xsl:apply-templates select="cbc:EndpointID"/>
			<xsl:apply-templates select="cac:PartyIdentification"/>
			<xsl:apply-templates select ="cac:PartyName"/>
			<xsl:apply-templates select="cac:PostalAddress"/>
			<xsl:choose>
				<xsl:when test="cac:PartyLegalEntity">
					<xsl:apply-templates select="cac:PartyLegalEntity" mode="DeliveryParty"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="PartyLegalEntityDelivery"/>
				</xsl:otherwise>		
			</xsl:choose>
			<xsl:apply-templates select="cac:Contact"/>
			<xsl:apply-templates select="cac:Person"/>
			<xsl:apply-templates select="cac:ServiceProviderParty"/>
		</cac:DeliveryParty>
		
	</xsl:template>
	
	<xsl:template match="cac:PartyLegalEntity" mode="DeliveryParty">
		<cac:PartyLegalEntity>
			<xsl:choose>
				<xsl:when test="cbc:RegistrationName and normalize-space(cbc:RegistrationName) != ''" >
					<xsl:apply-templates select="cbc:RegistrationName" mode="DeliveryParty"/>
				</xsl:when>			
				<xsl:otherwise>
					<xsl:call-template name="DeliveryPartyCompanyID"/>	
				</xsl:otherwise>
			</xsl:choose>
			
			<xsl:choose>
				<xsl:when test="cbc:CompanyID and normalize-space(cbc:CompanyID) != ''" >
					<xsl:apply-templates select="cbc:CompanyID" mode="DeliveryParty"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="DeliveryPartyCompanyID"/>
				</xsl:otherwise>
			</xsl:choose>	
		</cac:PartyLegalEntity>
		
	</xsl:template>
	
	<xsl:template name="PartyLegalEntityDelivery">
		<cac:PartyLegalEntity>
			<xsl:call-template name="DeliveryPartyRegistrationName"/>
			<xsl:call-template name="DeliveryPartyCompanyID"/>
		</cac:PartyLegalEntity>
	</xsl:template>
	
	<xsl:template name="DeliveryPartyRegistrationName">
		<cbc:RegistrationName>
			<xsl:value-of select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:RegistrationName"/>
		</cbc:RegistrationName>
	</xsl:template>
	
	<xsl:template match="cbc:CompanyID" mode="DeliveryParty">
		<cbc:CompanyID>
			<xsl:value-of select="."/>
		</cbc:CompanyID>
	</xsl:template>
	
	<xsl:template name="DeliveryPartyCompanyID">
		<cbc:CompanyID>
			<xsl:value-of select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/cbc:CompanyID"/>
		</cbc:CompanyID>
	</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:DeliveryLocation">
		<xsl:if test="cac:Address" >
			<cac:DeliveryAddress>
				<xsl:apply-templates select="cac:Address/cbc:StreetName" />
				<xsl:apply-templates select="cac:Address/cbc:CityName" />
				<xsl:apply-templates select="cac:Address/cbc:PostalZone" />
				<xsl:apply-templates select="cac:Address/cbc:CountrySubentity" />
				<xsl:apply-templates select="cac:Address/cac:AddressLine" />
				<xsl:apply-templates select="cac:Address/cac:Country" />
			
			</cac:DeliveryAddress>
		</xsl:if>
	
	</xsl:template>

	<xsl:template match="cac:Address">
		<cac:Address>
			<xsl:apply-templates select="cbc:StreetName" />
			<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:PartyIdentification"  />
			<xsl:apply-templates select="cac:PartyName[normalize-space(cbc:Name/text()) != '']" />
			<xsl:apply-templates select="cac:PartyLegalEntity" mode="PayeeParty" />
		
		</cac:PayeeParty>
	
	</xsl:template>
	
	<xsl:template match="cac:PartyLegalEntity" mode="PayeeParty" >
		<cac:PartyLegalEntity>
			<xsl:apply-templates select="cbc:CompanyID" mode="SchemeID" />
		
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template match="cac:PartyIdentification" mode="PayeeParty" >
		<cac:PartyIdentification>
			<xsl:apply-templates select="cbc:ID" mode="SchemeID" />
		</cac:PartyIdentification>
	
	</xsl:template>
	
	<xsl:template match="cac:AccountingCustomerParty">
		<cac:AccountingCustomerParty>
		
			<xsl:apply-templates select="cac:Party" mode="AccountingCustomerParty" />
			<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" />
			<!--<xsl:apply-templates select="cbc:ElectronicMail" />-->
			<xsl:call-template name="CustomerElectronicMail" />
			<!--<xsl:apply-templates select="/c:CreditNote/cbc:Note" mode="OznakaOperatera" />-->
		</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:apply-templates select="cac:PartyLegalEntity/cbc:CompanyID" mode="EndpointID" />-->
			<!--<xsl:call-template name="EndpointID" />-->
			<xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/>

			<!--<xsl:apply-templates select="cac:PartyLegalEntity/cbc:CompanyID" mode="PartyIdentification" />-->
			<!--<xsl:apply-templates select="cac:PartyIdentification" />-->
			<!--<xsl:apply-templates select="cac:PartyName" />-->
			<xsl:call-template name="PartyName" />
			<xsl:apply-templates select="cac:PostalAddress" />
			<!--<xsl:call-template name="PartyTaxScheme" />-->
			<!--<xsl:apply-templates select="cac:PartyLegalEntity" mode="AccountingCustomerParty" />-->
			<xsl:call-template name="AccountingCustomerPartyLegalEntity" />
			<xsl:apply-templates select="cac:PartyIdentification" />
			<!--<xsl:call-template name="PartyContact" />-->
		
		</cac:Party>
	
	</xsl:template>
	
	<xsl:template name="AccountingCustomerPartyLegalEntity" >
		<cac:PartyLegalEntity>
			<xsl:apply-templates select="//cac:AccountingCustomerParty/cac:Party/cac:PartyLegalEntity/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="cac:Party" mode="AccountingSupplierParty" />
			<xsl:call-template name="AccountingSupplierPartyContact"/>
		
		</cac:AccountingSupplierParty>
	
	</xsl:template>
	
	<xsl:template name="AccountingSupplierPartyContact" >
		<cac:AccountingContact>
			<xsl:call-template name="SupplierResponsiblePerson"/>
			<xsl:call-template name="SupplierOperator"/>
		</cac:AccountingContact>
	</xsl:template>
	
	<xsl:template name="SupplierResponsiblePerson">
		<cbc:Name>
			<xsl:choose>
				<xsl:when test="normalize-space($responsiblePerson) != ''">
					<xsl:value-of select="$responsiblePerson"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$operator"/>
				</xsl:otherwise>
			</xsl:choose>
		</cbc:Name>
		
	</xsl:template>
	
	<xsl:template name="SupplierOperator">
		<cbc:Note>
			<xsl:choose>
				<xsl:when test="normalize-space($operator) != ''">
					<xsl:value-of select="$operator"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$responsiblePerson"/>
				</xsl:otherwise>
			</xsl:choose>
		</cbc:Note>
		
	</xsl:template>	
	
	<xsl:template match="cac:Party" mode="AccountingSupplierParty" >
		<cac:Party>
			<!--<xsl:apply-templates select="cac:PartyLegalEntity/cbc:CompanyID" mode="EndpointID" />-->
			<xsl:apply-templates select="cbc:EndpointID" mode="SchemeID"/>
			<!--<xsl:apply-templates select="cac:PartyLegalEntity/cbc:CompanyID" mode="PartyIdentification" />-->
			<!--<xsl:apply-templates select="cac:PartyName" />-->
			<xsl:call-template name="PartyName" />
			<xsl:apply-templates select="cac:PostalAddress" />
			<!--<xsl:call-template name="PartyTaxScheme" />-->
			<!--<xsl:apply-templates select="cac:PartyLegalEntity" mode="AccountingSupplierParty"/>-->
			<xsl:call-template name="AccountingSupplierPartyLegalEntity" />
			<xsl:apply-templates select="cac:PartyIdentification" />
			<!--<xsl:call-template name="PartyContact" />-->
		
		</cac:Party>
	
	</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:CompanyID>
				<xsl:value-of select="$supplierCompanyId" />
			</cbc:CompanyID>

		
		</cac:PartyLegalEntity>
	
	</xsl:template>
	
	<xsl:template name="PartyName" >
		<xsl:choose>
			<xsl:when test="cac:PartyName/cbc:Name and (normalize-space(cac:PartyName/cbc:Name) != '')">
				<xsl:apply-templates select="cac:PartyName[normalize-space(cbc:Name/text()) != '']" />
			</xsl:when>
			<xsl:when test="cac:PartyLegalEntity/cbc:RegistrationName and (normalize-space(cac:PartyLegalEntity/cbc:RegistrationName) != '')">
				<cac:PartyName>
					<cbc:Name><xsl:value-of select="normalize-space(cac:PartyLegalEntity/cbc:RegistrationName)" /></cbc:Name>
				</cac:PartyName>
			</xsl:when>
		
		</xsl:choose>
	
	</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:StreetName" />
			<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" />
		
		</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">
		<cac:AddressLine>
			<xsl:apply-templates select="cbc:Line" />
		</cac:AddressLine>
	
	</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:PartyIdentification" >
		<xsl:if test="cbc:ID and (normalize-space(cbc:ID) != '')">
			
			<xsl:variable name="id1" select="substring-after(cbc:ID, ':')" />
			<xsl:variable name="id2" select="substring-after($id1, '::HR99:')" />
			<xsl:choose>
				<xsl:when test="normalize-space($id2) != ''">
					<cac:PartyIdentification>
						<cbc:ID><xsl:value-of select="$id2" /></cbc:ID>
					</cac:PartyIdentification>	
				</xsl:when>
				<!--<xsl:when test="normalize-space($id1) != ''"><cbc:ID><xsl:value-of select="$id1" /></cbc:ID></xsl:when>
				<xsl:otherwise><cbc:ID><xsl:value-of select="cbc:ID" /></cbc:ID></xsl:otherwise>-->
			</xsl:choose>
				
		
		</xsl:if>
	</xsl:template>
	
	
	<xsl:template match="cac:ProjectReference" >
		<cac:ProjectReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:ProjectReference>
	
	</xsl:template>

	
	<xsl:template match="cac:ContractDocumentReference" >
		<cac:ContractDocumentReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:ContractDocumentReference>
	
	</xsl:template>
	
	<xsl:template match="cac:OriginatorDocumentReference" >
		<cac:OriginatorDocumentReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:OriginatorDocumentReference>
	
	</xsl:template>
	
	<xsl:template match="cac:ReceiptDocumentReference" >
		<cac:ReceiptDocumentReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:ReceiptDocumentReference>
	
	</xsl:template>
	
	<xsl:template match="cac:DespatchDocumentReference" >
		<cac:DespatchDocumentReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
		</cac:DespatchDocumentReference>
	
	</xsl:template>
	
	<xsl:template match="cac:BillingReference" >
		<cac:BillingReference>
			<xsl:apply-templates select="cac:InvoiceDocumentReference" />
		
		</cac:BillingReference>	
	
	</xsl:template>
	
	<xsl:template match="cac:InvoiceDocumentReference" >
		<cac:InvoiceDocumentReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
			<xsl:apply-templates select="cbc:IssueDate" />
		</cac:InvoiceDocumentReference>
	
	</xsl:template>
	
	<xsl:template match="cac:OrderReference" >
		<cac:OrderReference>
			<xsl:apply-templates select="cbc:ID" mode="ID" />
			<xsl:apply-templates select="cbc:SalesOrderReference" />		
		</cac:OrderReference>
	
	</xsl:template>
	
	<xsl:template match="cac:OrderReference/cbc:SalesOrderID">
		<cac:AdditionalDocumentReference>
			<cbc:ID><xsl:value-of select="."/></cbc:ID>
			<cbc:DocumentType>SalesOrderID</cbc:DocumentType>
		</cac:AdditionalDocumentReference>
		
	</xsl:template>
	
	<xsl:template match="cac:InvoicePeriod" >
		<cac:InvoicePeriod>
			<xsl:apply-templates select="cbc:StartDate" />
			<xsl:apply-templates select="cbc:EndDate" />
			<!--<xsl:apply-templates select="cbc:DescriptionCode" />-->
		
		</cac:InvoicePeriod>
	
	</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>
	
	
	
	<!-- 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:when test="normalize-space(substring-after(., 'Oznaka operatera:')) != ''" />
			<xsl:when test="normalize-space(substring-after(., 'Odgovorna osoba:')) != ''" />
			<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: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:value-of select="format-number(number(.), '#.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(.), '#.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="number(.) &gt; 1"><xsl:value-of select="format-number(number(.)  div 100,'0.0000')"/></xsl:when>
				<xsl:otherwise><xsl:value-of select="number(.)" /></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">
		<xsl:if test="@schemeID and (normalize-space(@schemeID) = '0088')">
			<cbc:EndpointID schemeID="GLN">
				<xsl:value-of select="." />
			</cbc:EndpointID>
		
		</xsl:if>
<!--		<cbc:EndpointID>
			<xsl:choose>
				<xsl:when test="@schemeID and (normalize-space(@schemeID) != '9934')">
					<xsl:attribute name="schemeID" namespace="">
						<xsl:value-of select="@schemeID" />
					</xsl:attribute>
				</xsl:when>
				<xsl:otherwise>
					<xsl:attribute name="schemeID" namespace="">9934</xsl:attribute>			
				</xsl:otherwise>
			</xsl:choose>
			<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:element name="{name(.)}" namespace="{namespace-uri(.)}">
			<xsl:value-of select="." />
		</xsl:element>
		

	</xsl:template>
</xsl:stylesheet>
