Clique na caixa expansão desejada para acessar o Datasul:
CTe104a_RetReceb_SefazToDatasul.xls
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng cte" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:cte="http://www.portalfiscal.inf.br/cte">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/></DateTime>
<TrackingNumber>
<ng:counter name="EAITrackingNumber" format="0000000"/>
</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>cteTiposBasico</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<xsl:copy>
<xsl:choose>
<xsl:when test="boolean(cte:cteProc)">
<xsl:apply-templates select="cte:cteProc/cte:CTe"/>
</xsl:when>
<xsl:when test="boolean(cteProc/cte:CTe)">
<xsl:apply-templates select="cteProc/cte:CTe"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="cteProc/CTe"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="boolean(cte:cteProc)">
<xsl:apply-templates select="cte:cteProc/cte:protCTe"/>
</xsl:when>
<xsl:when test="boolean(cteProc/cte:protCTe)">
<xsl:apply-templates select="cteProc/cte:protCTe"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="cteProc/protCTe"/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="..\..\..\neo40386\Desktop\XML\retNFeAuthorized_20070912123509428.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe_MsgInvalida_DatasulToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/TrackingId/DateTime"/></DateTime>
<TrackingNumber><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/TrackingId/TrackingNumber"/></TrackingNumber>
</TrackingId>
<Product>
<Name><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Product/Name"/></Name>
<Version><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Product/Version"/></Version>
</Product>
<Application><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Application"/></Application>
<Name><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Name"/></Name>
<Version><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Version"/></Version>
<Action><xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Action"/></Action>
<ListOfKeyField>
<keyField Name=""/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain><xsl:value-of select="DatasulMessage/MessageHeader/CompanyId/Domain"/></Domain>
<BusinessIdentifier><xsl:value-of select="DatasulMessage/MessageHeader/CompanyId/BusinessIdentifier"/></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>NO</IsMessageProcessed>
<ListOfError>
<Error>
<Id>0</Id>
<Type>validation_error</Type>
<Desc>O NeoGrid NF-e não está configurado para processar a mensagem do tipo <xsl:value-of select="DatasulMessage/MessageHeader/TransactionId/Name"/>.</Desc>
</Error>
</ListOfError>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file://c:\NF-e\queues\CaracterEspecial1_cm2.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->
NFe005_Canc_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<cancNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/CancNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/CancNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/cancNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/cancNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.07</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infCanc>
<xsl:choose>
<xsl:when test="boolean(DatasulMessage/BusinessContent/Upsert/CancNFe)">
<xsl:attribute name="Id">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/Id)"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>CANCELAR</xServ>
<chNFe>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/chNFe)"/>
</chNFe>
<nProt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/nProt"/>
</nProt>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Cancelamento: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/xJust),'1','227')))"/>
</xJust>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Id">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/Id)"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>CANCELAR</xServ>
<chNFe>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/chNFe)"/>
</chNFe>
<nProt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/nProt"/>
</nProt>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Cancelamento: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/xJust),'1','227')))"/>
</xJust>
</xsl:otherwise>
</xsl:choose>
</infCanc>
</cancNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Users/bsoares/Desktop/New Folder (3)/xml-cancelamento-nota-nfe2.00.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="cancNFe_v1.06.xsd" destSchemaRoot="cancNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="CancelInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_Cons_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform " xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<consSitNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:attribute name="versao">2.00</xsl:attribute>
<tpAmb>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/ConsSitNFe/tpAmb)"/>
</tpAmb>
<xServ>CONSULTAR</xServ>
<chNFe>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/ConsSitNFe/chNFe)"/>
</chNFe>
</consSitNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Users/bsoares/Desktop/Consulta.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="..\..\AD-Datasul\NF-e\SEFAZ\consSitNFe_v1.06.xsd" destSchemaRoot="ConsSitNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\..\AD-Datasul\NF-e\Datasul\NF-e\ConsultInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_Env_DatasulToSefaz.xsl
<?xml version='1.0' encoding='ISO-8859-1' ?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<ng:setVariable name="NumSeg">0</ng:setVariable>
<infNFe>
<xsl:attribute name="versao">1.10</xsl:attribute>
<xsl:attribute name="Id">NFe<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/></xsl:attribute>
<ide>
<cUF>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateId)"/>
</cUF>
<cNF>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'35','9')"/>
</cNF>
<natOp>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/FiscalOperation/FiscalOperationDescription),'1','60'))"/>
</natOp>
<indPag>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '2'">0</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '3'">2</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</indPag>
<mod>55</mod>
<xsl:variable name="serie" select="number(normalize-space(DatasulMessage/BusinessContent/Upsert/DocumentSeries))"/>
<serie>
<xsl:choose>
<xsl:when test="string-length($serie) > 3">
<xsl:value-of select="substring($serie, '1', '3')"/>
</xsl:when>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/DocumentSeries) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$serie"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNF>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/DocumentNumber)"/>
</nNF>
<dEmi>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/PrintDate"/>
</dEmi>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate!=''">
<dSaiEnt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate"/>
</dSaiEnt>
</xsl:if>
<tpNF>
<xsl:variable name="FOCFOP" select="substring(DatasulMessage/BusinessContent/Upsert/ListOfDocumentItens/DocumentItem/FiscalOperation/FiscalOperationCFOP, '1', '1')"/>
<xsl:choose>
<xsl:when test="$FOCFOP = '1' or $FOCFOP = 2 or $FOCFOP = 3">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpNF>
<cMunFG>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMunFG>
<tpImp>
<xsl:choose>
<xsl:when test="string-length(normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)) > 0">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpImp>
<tpEmis>
<xsl:variable name="iniSerial">900</xsl:variable>
<xsl:variable name="finSerial">999</xsl:variable>
<xsl:variable name="tpEmis" select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted)"/>
<xsl:choose>
<xsl:when test="$tpEmis = '2' ">
<xsl:value-of select="$tpEmis"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpEmis>
<cDV>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'44','1')"/>
</cDV>
<tpAmb>1</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>5.0</verProc>
</ide>
<emit>
<CNPJ>
<xsl:value-of select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteTaxID,'.',''),'/',''),'-','')"/>
</CNPJ>
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteDescription),'1','60'))"/>
</xNome>
<enderEmit>
<xsl:variable name="streetAddress" select="DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress"/>
<xsl:choose>
<xsl:when test="$streetAddress != ''">
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddressNumber),'1','60'))"/>
</nro>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement != ''">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement),'1','60'))"/>
</xCpl>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="nroEmit" select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,','))"/>
<xLgr>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,',')">
<xsl:value-of select="normalize-space(substring(normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,',')),'1','60'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress),'1','60'))"/>
</xsl:otherwise>
</xsl:choose>
</xLgr>
<nro>
<xsl:choose>
<xsl:when test="contains($nroEmit,',')">
<xsl:value-of select="normalize-space(substring(normalize-space(substring-before($nroEmit,',')),'1','60'))"/>
</xsl:when>
<xsl:when test="string-length($nroEmit) > 0">
<xsl:value-of select="normalize-space(substring(normalize-space($nroEmit),'1','60'))"/>
</xsl:when>
<xsl:otherwise>s/n</xsl:otherwise>
</xsl:choose>
</nro>
<xsl:if test="contains($nroEmit,',')">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(substring-after($nroEmit,',')),'1','60'))"/>
</xCpl>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateCode,$minusculas,$maiusculas))"/>
</UF>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryID != ''">
<cPais>1058</cPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryName != ''">
<xPais>Brasil</xPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber!=''">
<fone>
<xsl:variable name="Fone">
<xsl:value-of select="translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber,' ',''),'-','')"/>
</xsl:variable>
<xsl:variable name="EmitFone" select="translate(translate(translate(translate(translate($Fone,'(',''),')',''),'.',''),',',''),'/','')"/>
<xsl:choose>
<xsl:when test="substring($EmitFone,'1','1')='0'">
<xsl:value-of select="substring($EmitFone,'2','10')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($EmitFone,'1','10')"/>
</xsl:otherwise>
</xsl:choose>
</fone>
</xsl:if>
</enderEmit>
<IE>
<xsl:choose>
<xsl:when test="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID) = 'ISENTO'">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</xsl:otherwise>
</xsl:choose>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID != ''">
<IEST>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</IEST>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID != '' or DatasulMessage/BusinessContent/Upsert/Site/SiteCNAEID != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID != ''">
<IM>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID)"/>
</IM>
</xsl:when>
<xsl:otherwise>
<CNAE>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCNAEID)"/>
</CNAE>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</emit>
<xsl:variable name="destId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="destcMun" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
<xsl:variable name="destUF" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode)"/>
<xsl:variable name="destBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName='' and $destcMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<ng:setVariable name="destA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="address">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$address != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="destN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressSupplement"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="nro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($nro,',')">
<ng:setVariable name="destN">
<xsl:value-of select="substring-before($nro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($nro) > 0">
<ng:setVariable name="destN">
<xsl:value-of select="$nro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="normalize-space(substring-after($nro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="destAddress">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:variable name="destNro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:variable name="destCpl">
<ng:getVariable name="destC"/>
</xsl:variable>
<dest>
<xsl:choose>
<xsl:when test="string-length($destId) = 11">
<CPF>
<xsl:value-of select="$destId"/>
</CPF>
</xsl:when>
<xsl:when test="$destcMun = '9999999'">
<CNPJ>
</CNPJ>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$destId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerName),'1','60'))"/>
</xNome>
<enderDest>
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space($destAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space($destNro),'1','60'))"/>
</nro>
<xsl:if test="$destCpl != ''">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space($destCpl),'1','60'))"/>
</xCpl>
</xsl:if>
<xBairro>
<xsl:choose>
<xsl:when test="$destBairro != ''">
<xsl:value-of select="normalize-space(substring(normalize-space($destBairro),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId = '9999999'">
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>EXTERIOR</xMun>
<UF>EX</UF>
</xsl:when>
<xsl:otherwise>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas))"/>
</UF>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CustomerCountryID != ''">
<cPais>
<xsl:value-of select="normalize-space(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CustomerCountryID))"/>
</cPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName != ''">
<xPais>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName),'1','60'))"/>
</xPais>
</xsl:if>
</enderDest>
<IE>
<xsl:choose>
<xsl:when test="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID) = 'ISENTO'">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</xsl:otherwise>
</xsl:choose>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode != ''">
<ISUF>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode),'1','9'))"/>
</ISUF>
</xsl:if>
</dest>
<!-- A TAG DeliveryLocation é opcional, deve ser validado se foi enviado algum conteúdo nesta TAG antes de montar as informações -->
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation != ''">
<xsl:variable name="entregaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/LocationTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="entregaIE" select="normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/LocationStateTaxID,'.',''),'/',''),'-',''))"/>
<xsl:variable name="entregacMun" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
<xsl:variable name="entregaUF" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode)"/>
<xsl:variable name="entregaBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName='' and $entregacMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="destAddr" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address"/>
<xsl:variable name="entregaAddr" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address"/>
<xsl:variable name="entregaCEP" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/ZipCode)"/>
<xsl:variable name="entregaCpl" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressSupplement"/>
<ng:setVariable name="entregaA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="eAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$eAddress != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="entregaN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="eNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($eNro,',')">
<ng:setVariable name="entregaN">
<xsl:value-of select="substring-before($eNro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($eNro) > 0">
<ng:setVariable name="entregaN">
<xsl:value-of select="$eNro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaCpl">
<xsl:value-of select="normalize-space(substring-after($eNro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="entregaAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:variable name="entregaNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation != '' and ($entregaId != $destId or $destAddr != $entregaAddr)">
<entrega>
<xsl:choose>
<xsl:when test="$entregaUF = 'EX'">
<CNPJ>00000000000000</CNPJ>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="format-number($entregaId, '00000000000000')"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="nroEntrega" select="normalize-space(substring-after (DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space($entregaAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space($entregaNro),'1','60'))"/>
</nro>
<xCpl>
<xsl:choose>
<xsl:when test="$entregaCpl != ''">
<xsl:value-of select="concat(normalize-space(substring(normalize-space($entregaCpl),'1','60')), ', IE: ', $entregaIE, ', CEP: ', $entregaCEP)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('nao informado, IE: ', $entregaIE, ', CEP: ', $entregaCEP)"/>
</xsl:otherwise>
</xsl:choose>
</xCpl>
<xBairro>
<xsl:choose>
<xsl:when test="$entregaBairro != ''">
<xsl:value-of select="normalize-space(substring(normalize-space($entregaBairro),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space (DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas))"/>
</UF>
</entrega>
</xsl:if>
</xsl:if>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentItens/DocumentItem">
<xsl:variable name="cont">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<ng:setVariable name="NumSeg">
<xsl:value-of select="$cont + 1"/>
</ng:setVariable>
<det>
<xsl:attribute name="nItem">
<xsl:variable name="conta">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<xsl:value-of select="$conta"/>
</xsl:attribute>
<prod>
<cProd>
<xsl:choose>
<xsl:when test="Item/ItemCode != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(Item/ItemCode),'1','60'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</cProd>
<cEAN>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEAN>
<xProd>
<xsl:value-of select="normalize-space(substring(normalize-space(Item/ItemDescription),'1','120'))"/>
</xProd>
<xsl:if test="FiscalClassification/FiscalClassificationID != ''">
<NCM>
<xsl:value-of select="format-number(FiscalClassification/FiscalClassificationID,'00000000')"/>
</NCM>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/EX_TIPIID != ''">
<EXTIPI>
<xsl:value-of select="format-number(AdditionalInformationTaxes/EX_TIPIID,'000')"/>
</EXTIPI>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/Gender != ''">
<genero>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/Gender)"/>
</genero>
</xsl:if>
<CFOP>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
</xsl:choose>
</CFOP>
<uCom>
<xsl:value-of select="normalize-space(substring(normalize-space(UnitOfMeasure/UnitOfMeasureCode),'1','6'))"/>
</uCom>
<qCom>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qCom>
<vUnCom>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnCom>
<vProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/GoodsTotalValues/NetPrice,'0.00')"/>
</vProd>
<cEANTrib>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEANTrib>
<uTrib>
<xsl:choose>
<xsl:when test="CustomerUnitOfMeasure/UnitOfMeasureCode != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(CustomerUnitOfMeasure/UnitOfMeasureCode),'1','6'))"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</uTrib>
<qTrib>
<xsl:choose>
<xsl:when test="CustomerInvoicedQuantity != ''">
<xsl:value-of select="format-number(CustomerInvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qTrib>
<vUnTrib>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnTrib>
<xsl:if test="ItemValuesAndTaxes/FreightValue != '' and ItemValuesAndTaxes/FreightValue != '0'">
<vFrete>
<xsl:value-of select="format-number(ItemValuesAndTaxes/FreightValue,'0.00')"/>
</vFrete>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount != '' and ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount != '0'">
<vDesc>
<xsl:value-of select="format-number(ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount,'0.00')"/>
</vDesc>
</xsl:if>
<xsl:if test="ImportDocument/ImportDocumentNumber != ''">
<DI>
<nDI>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentNumber),'1','10'))"/>
</nDI>
<dDI>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentDate)"/>
</dDI>
<xLocDesemb>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentClearanceLocation),'1','60'))"/>
</xLocDesemb>
<UFDesemb>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentClearanceState)"/>
</UFDesemb>
<dDesemb>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentClearanceDate)"/>
</dDesemb>
<cExportador>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentExporterCode),'1','60'))"/>
</cExportador>
<xsl:for-each select="ImportDocument/ImportDocumentAdd">
<adi>
<nAdicao>
<xsl:value-of select="normalize-space(ImportDocumentAddNumber)"/>
</nAdicao>
<nSeqAdic>
<xsl:value-of select="normalize-space(ImportDocumentAddSequence)"/>
</nSeqAdic>
<cFabricante>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocumentManufacturerID),'1','60'))"/>
</cFabricante>
<xsl:if test="ImportDocumentDiscount != ''">
<vDescDI>
<xsl:value-of select="normalize-space(ImportDocumentDiscount)"/>
</vDescDI>
</xsl:if>
</adi>
</xsl:for-each>
</DI>
</xsl:if>
<xsl:choose>
<xsl:when test="ItemVehicle/VehicleTypeOperation != ''">
<veicProd>
<tpOp>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleTypeOperation)"/>
</tpOp>
<chassi>
<xsl:value-of select="substring(ItemVehicle/VehicleID, '1', '17')"/>
</chassi>
<cCor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleColorID),'1','4'))"/>
</cCor>
<xCor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleColorName),'1','40'))"/>
</xCor>
<pot>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleMotorPower),'1','4'))"/>
</pot>
<CM3>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehiclePower),'1','4'))"/>
</CM3>
<pesoL>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleNetWeight),'1','9'))"/>
</pesoL>
<pesoB>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleGrossWeight),'1','9'))"/>
</pesoB>
<nSerie>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleSerialNumber),'1','9'))"/>
</nSerie>
<tpComb>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleFuel),'1','8'))"/>
</tpComb>
<nMotor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleMotorNumber),'1','21'))"/>
</nMotor>
<CMKG>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleCMKG),'1','9'))"/>
</CMKG>
<dist>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleDistance),'1','4'))"/>
</dist>
<xsl:if test="ItemVehicle/VehicleRENAVAN != ''">
<RENAVAM>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleRENAVAN),'1','9'))"/>
</RENAVAM>
</xsl:if>
<anoMod>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleModelYear)"/>
</anoMod>
<anoFab>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleFabricatedYear)"/>
</anoFab>
<tpPint>
<xsl:value-of select="normalize-space(ItemVehicle/VehiclePaintID)"/>
</tpPint>
<tpVeic>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleType)"/>
</tpVeic>
<espVeic>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleEspecie)"/>
</espVeic>
<VIN>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleIdentificationNumber)"/>
</VIN>
<condVeic>
<xsl:choose>
<xsl:when test="ItemVehicle/VehicleCondition = 1 or ItemVehicle/VehicleCondition = 2 or ItemVehicle/VehicleCondition = 3">
<xsl:value-of select="normalize-space(ItemVehicle/VehicleCondition)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</condVeic>
<cMod>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleModel)"/>
</cMod>
</veicProd>
</xsl:when>
<xsl:when test="ItemMedicine/MedicineLotNumber != '' or ItemMedicine/MedicineQuantity != '' or ItemMedicine/MedicineFabricantedDate != '' or ItemMedicine/MedicineValidityDate != '' or ItemMedicine/MedicineMaxConsumerPrice != ''">
<xsl:for-each select="ItemMedicine">
<med>
<nLote>
<xsl:value-of select="normalize-space(MedicineLotNumber)"/>
</nLote>
<qLote>
<xsl:value-of select="normalize-space(format-number(MedicineQuantity,'0.000'))"/>
</qLote>
<dFab>
<xsl:value-of select="normalize-space(MedicineFabricatedDate)"/>
</dFab>
<dVal>
<xsl:value-of select="normalize-space(MedicineValidityDate)"/>
</dVal>
<vPMC>
<xsl:value-of select="normalize-space(format-number(MedicineMaxConsumerPrice,'0.00'))"/>
</vPMC>
</med>
</xsl:for-each>
</xsl:when>
<xsl:when test="ItemFuel/FuelID != ''">
<comb>
<xsl:if test="ItemFuel/FuelID != ''">
<cProdANP>
<xsl:value-of select="normalize-space(ItemFuel/FuelID)"/>
</cProdANP>
</xsl:if>
<xsl:if test="ItemFuel/FuelCODIF != ''">
<CODIF>
<xsl:value-of select="normalize-space(ItemFuel/FuelCODIF)"/>
</CODIF>
</xsl:if>
<xsl:if test="ItemFuel/FuelQuantity != ''">
<qTemp>
<xsl:value-of select="normalize-space(ItemFuel/FuelQuantity)"/>
</qTemp>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDECalculationBasis != '' or ItemFuel/FuelCIDEPercentage != '' or ItemFuel/FuelCIDEValue != ''">
<CIDE>
<xsl:if test="ItemFuel/FuelCIDECalculationBasis != ''">
<qBCProd>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDECalculationBasis,'0.0000'))"/>
</qBCProd>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDEPercentage != ''">
<vAliqProd>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDEPercentage,'0.0000'))"/>
</vAliqProd>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDEValue != ''">
<vCIDE>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDEValue,'0.00'))"/>
</vCIDE>
</xsl:if>
</CIDE>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSCalculationBasis != '' or ItemFuel/FuelICMSValue != '' or ItemFuel/FuelICMSSubstitutionBasis != '' or ItemFuel/FuelICMSSubstitutionValue != ''">
<ICMSComb>
<xsl:if test="ItemFuel/FuelICMSCalculationBasis != ''">
<vBCICMS>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSCalculationBasis,'0.00'))"/>
</vBCICMS>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSValue != ''">
<vICMS>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSValue,'0.00'))"/>
</vICMS>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSSubstitutionBasis != ''">
<vBCICMSST>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSSubstitutionBasis,'0.00'))"/>
</vBCICMSST>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSSubstitutionValue != ''">
<vICMSST>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSSubstitutionValue,'0.00'))"/>
</vICMSST>
</xsl:if>
</ICMSComb>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionBasis != '' or ItemFuel/FuelICMSFateSubstitutionValue != ''">
<ICMSInter>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionBasis != ''">
<vBCICMSSTDest>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSFateSubstitutionBasis,'0.00'))"/>
</vBCICMSSTDest>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionValue != ''">
<vICMSSTDest>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSFateSubstitutionValue,'0.00'))"/>
</vICMSSTDest>
</xsl:if>
</ICMSInter>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSConsumSubstitutionBasis != '' or ItemFuel/FuelICMSConsumSubstitutionValue != '' or ItemFuel/FuelConsumptionStateID != ''">
<ICMSCons>
<vBCICMSSTCons>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSConsumSubstitutionBasis,'0.00'))"/>
</vBCICMSSTCons>
<vICMSSTCons>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSConsumSubstitutionValue,'0.00'))"/>
</vICMSSTCons>
<UFCons>
<xsl:value-of select="normalize-space(ItemFuel/FuelConsumptionStateID)"/>
</UFCons>
</ICMSCons>
</xsl:if>
</comb>
</xsl:when>
</xsl:choose>
</prod>
<imposto>
<ICMS>
<xsl:choose>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '10'">
<ICMS10>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS10>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '20'">
<ICMS20>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS20>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '30'">
<ICMS30>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS30>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '40' or substring(StatusTaxIcms,'2','2') = '41' or substring(StatusTaxIcms,'2','2') = '50'">
<ICMS40>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
</ICMS40>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '51'">
<ICMS51>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS51>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '60'">
<ICMS60>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS60>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '70'">
<ICMS70>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS70>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '90'">
<ICMS90>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
</xsl:choose>
</pRedBC>
</xsl:if>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS90>
</xsl:when>
<xsl:otherwise>
<ICMS00>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:choose>
<xsl:when test="string-length(StatusTaxIcms) = 3">
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</xsl:when>
<xsl:otherwise>00</xsl:otherwise>
</xsl:choose>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS00>
</xsl:otherwise>
</xsl:choose>
</ICMS>
<xsl:if test="StatusTaxIpi != ''">
<IPI>
<xsl:if test="AdditionalInformationTaxes/IPIFrameworkClass != ''">
<clEnq>
<xsl:value-of select="normalize-space(substring(normalize-space(AdditionalInformationTaxes/IPIFrameworkClass),'1','5'))"/>
</clEnq>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/ProducerTaxID != ''">
<CNPJProd>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/ProducerTaxID)"/>
</CNPJProd>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/IPISealID != ''">
<cSelo>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPISealID)"/>
</cSelo>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/IPISealQuantity != ''">
<qSelo>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPISealQuantity)"/>
</qSelo>
</xsl:if>
<xsl:choose>
<xsl:when test="AdditionalInformationTaxes/IPIFrameworkID != ''">
<cEnq>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPIFrameworkID)"/>
</cEnq>
</xsl:when>
<xsl:otherwise>
<cEnq>999</cEnq>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '01' or StatusTaxIpi = '02' or StatusTaxIpi = '03' or StatusTaxIpi = '04' or StatusTaxIpi = '05' or StatusTaxIpi = '51' or StatusTaxIpi = '52' or StatusTaxIpi = '53' or StatusTaxIpi = '54' or StatusTaxIpi = '55'">
<IPINT>
<CST>
<xsl:value-of select="StatusTaxIpi"/>
</CST>
</IPINT>
</xsl:when>
<xsl:otherwise>
<IPITrib>
<CST>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '00' or StatusTaxIpi = '49' or StatusTaxIpi = '50' or StatusTaxIpi = '99'">
<xsl:value-of select="StatusTaxIpi"/>
</xsl:when>
<xsl:otherwise>99</xsl:otherwise>
</xsl:choose>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pIPI>
<vIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
</IPITrib>
</xsl:otherwise>
</xsl:choose>
</IPI>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue!=''">
<II>
<vBC>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxCalculationBasis,'0.00')"/>
</vBC>
<vDespAdu>0</vDespAdu>
<vII>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue,'0.00')"/>
</vII>
<vIOF>0</vIOF>
</II>
</xsl:if>
<PIS>
<xsl:choose>
<xsl:when test="StatusTaxPis = '01' or StatusTaxPis = '02'">
<PISAliq>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISAliq>
</xsl:when>
<xsl:when test="StatusTaxPis = '03'">
<PISQtde>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISQtde>
</xsl:when>
<xsl:when test="StatusTaxPis = '04' or StatusTaxPis = '06' or StatusTaxPis = '07' or StatusTaxPis = '08' or StatusTaxPis = '09'">
<PISNT>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
</PISNT>
</xsl:when>
<xsl:otherwise>
<PISOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
</xsl:otherwise>
</xsl:choose>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISOutr>
</xsl:otherwise>
</xsl:choose>
</PIS>
<COFINS>
<xsl:choose>
<xsl:when test="StatusTaxCofins = '01' or StatusTaxCofins = '02'">
<COFINSAliq>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0.00</xsl:otherwise>
</xsl:choose>
</pCOFINS>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSAliq>
</xsl:when>
<xsl:when test="StatusTaxCofins = '03'">
<COFINSQtde>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSQtde>
</xsl:when>
<xsl:when test="StatusTaxCofins = '04' or StatusTaxCofins = '06' or StatusTaxCofins = '07' or StatusTaxCofins = '08' or StatusTaxCofins = '09'">
<COFINSNT>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
</COFINSNT>
</xsl:when>
<xsl:otherwise>
<COFINSOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pCOFINS>
</xsl:otherwise>
</xsl:choose>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSOutr>
</xsl:otherwise>
</xsl:choose>
</COFINS>
</imposto>
<xsl:if test="normalize-space(Narrative) != ''">
<infAdProd>
<xsl:value-of select="normalize-space(substring(normalize-space(Narrative),'1','500'))"/>
</infAdProd>
</xsl:if>
</det>
</xsl:for-each>
<total>
<ICMSTot>
<vBC>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<vICMS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<vBCST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vST>
<vProd>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vProd>
<vFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vFrete>
<vSeg>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vSeg>
<vDesc>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vDesc>
<vII>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vII>
<vIPI>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
<vPIS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
<vCOFINS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
<vOutro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Packaging/PackagingValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Packaging/PackagingValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vOutro>
<vNF>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Shipment/FreightType = '1'">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</modFrete>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID!='' and string-length(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID)='11' or string-length(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID)='14'">
<transporta>
<xsl:variable name="transportaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID,'.',''),'/',''),'-','')"/>
<xsl:choose>
<xsl:when test="string-length($transportaId) = 11">
<CPF>
<xsl:value-of select="$transportaId"/>
</CPF>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$transportaId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName != ''">
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName),'1','60'))"/>
</xNome>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID != ''">
<IE>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID),'1','14'))"/>
</IE>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName = '' and DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName != ''">
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName"/>
</xNome>
</xsl:if>
<xsl:variable name="street" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StreetAddress"/>
<xsl:if test="$street != ''">
<xsl:variable name="number" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressNumber"/>
<xsl:variable name="supplement" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressSupplement"/>
<xEnder>
<xsl:value-of select="normalize-space(substring(concat($street,' ',$number,' ',$supplement),'1','60'))"/>
</xEnder>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName != ''">
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode != ''">
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="UFTransp" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode"/>
<xsl:value-of select="normalize-space(translate($UFTransp,$minusculas,$maiusculas))"/>
</UF>
</xsl:if>
</transporta>
</xsl:if>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="veicPlaca" select="substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateID,'-',''),' ',''),$minusculas,$maiusculas)), '1', '8')"/>
<xsl:variable name="veicUF" select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateStateID,$minusculas,$maiusculas))"/>
<xsl:if test="$veicPlaca != '' and $veicUF != ''">
<veicTransp>
<placa>
<xsl:value-of select="$veicPlaca"/>
</placa>
<UF>
<xsl:value-of select="$veicUF"/>
</UF>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/RNTCID) != ''">
<RNTC>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/RNTCID)"/>
</RNTC>
</xsl:if>
</veicTransp>
</xsl:if>
<xsl:variable name="qVol" select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingQuantity"/>
<xsl:variable name="esp" select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingDescription"/>
<xsl:variable name="pesoL" select="DatasulMessage/BusinessContent/Upsert/DocumentNetWeight"/>
<xsl:variable name="pesoB" select="DatasulMessage/BusinessContent/Upsert/DocumentGrossWeight"/>
<xsl:if test="$qVol != '' or $esp != '' or $pesoL != '' or $pesoB != ''">
<vol>
<xsl:if test="$qVol != ''">
<qVol>
<xsl:value-of select="$qVol"/>
</qVol>
</xsl:if>
<xsl:if test="$esp != ''">
<esp>
<xsl:value-of select="normalize-space(substring(normalize-space($esp),'1','60'))"/>
</esp>
</xsl:if>
<xsl:if test="$pesoL != ''">
<pesoL>
<xsl:value-of select="format-number($pesoL,'0.000')"/>
</pesoL>
</xsl:if>
<xsl:if test="$pesoB != ''">
<pesoB>
<xsl:value-of select="format-number($pesoB,'0.000')"/>
</pesoB>
</xsl:if>
</vol>
</xsl:if>
</transp>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills != ''">
<cobr>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills/DocumentBill">
<dup>
<nDup>
<xsl:value-of select="normalize-space(substring(normalize-space(concat(BillNumber,'/',InstallmentNumber)),'1','60'))"/>
</nDup>
<dVenc>
<xsl:value-of select="DueDate"/>
</dVenc>
<vDup>
<xsl:value-of select="translate(format-number(InstallmentNetValue,'0.00'),',','.')"/>
</vDup>
</dup>
</xsl:for-each>
</cobr>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Narrative != '' or DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation != ''">
<infAdic>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation) != ''">
<infAdFisco>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation)"/>
</infAdFisco>
</xsl:if>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/Narrative) != ''">
<infCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Narrative),'1','5000'))"/>
</infCpl>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentID != ''">
<obsCont>
<xsl:attribute name="xCampo">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentID)"/>
</xsl:attribute>
<xTexto>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentContent)"/>
</xTexto>
</obsCont>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentID != ''">
<obsFisco>
<xsl:attribute name="xCampo">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentID)"/>
</xsl:attribute>
<xTexto>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentContent)"/>
</xTexto>
</obsFisco>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessID != '' or DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessOriginID != ''">
<procRef>
<nProc>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessID),'1','60'))"/>
</nProc>
<indProc>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessOriginID)"/>
</indProc>
</procRef>
</xsl:if>
</infAdic>
</xsl:if>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointStateId) != '' and normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointDescription) != ''">
<exporta>
<UFEmbarq>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointStateId)"/>
</UFEmbarq>
<xLocEmbarq>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointDescription),'1','60'))"/>
</xLocEmbarq>
</exporta>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerOrderNumber != ''">
<compra>
<xPed>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerOrderNumber),'1','60'))"/>
</xPed>
</compra>
</xsl:if>
</infNFe>
</NFe>
</xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="no" externalpreview="no" url="file:///c:/Documents and Settings/mgoncalves/Desktop/Datasul/35185.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
--><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="teste\35185.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="schemasSEFAZ\enviNFe_v1.08.xsd" destSchemaRoot="enviNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="schemasDatasul\NF-e\InvoiceDocument_204_000.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_Env_DatasulToSefaz_InvoiceNFe.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="ISO-8859-1"/>
<xsl:template match="/">
<xsl:for-each select="/DatasulMessage/BusinessContent/Upsert/*">
<xsl:choose>
<xsl:when test="local-name() = 'NFe'">
<xsl:element name="{name()}" namespace="http://www.portalfiscal.inf.br/nfe">
<xsl:copy-of select="*"/>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios/><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_Inut_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<inutNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/inutNFe[versao > '2.00' or versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/versao"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/InutNFe[versao > '2.00' or versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/InutNFe/versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.07</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infInut>
<xsl:variable name="serie">
<xsl:choose>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:attribute name="Id"><xsl:value-of select="concat('ID',DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF,substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2'),DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ,DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod,format-number($serie,'000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni,'000000000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin,'000000000'))"/></xsl:attribute>
<tpAmb>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/tpAmb"/>
</tpAmb>
<xServ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xServ"/>
</xServ>
<cUF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF"/>
</cUF>
<ano>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2')"/>
</ano>
<CNPJ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ"/>
</CNPJ>
<mod>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod"/>
</mod>
<serie>
<xsl:choose>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie)"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNFIni>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni)"/>
</nNFIni>
<nNFFin>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin)"/>
</nNFFin>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Inutilizacao: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xJust),'1','227')))"/>
</xJust>
</infInut>
</inutNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Users/bsoares/Desktop/Inut.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="..\Adapters\AD-Datasul\NF-e\SEFAZ\inutNFe_v1.06.xsd" destSchemaRoot="inutNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\Adapters\AD-Datasul\NF-e\Datasul\NF-e\InutInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetCanc_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>1.01.001</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/></DateTime>
<TrackingNumber/>
</TrackingId>
<Product>
<Name/>
<Version/>
</Product>
<Application/>
<Name/>
<Version/>
<Action/>
<ListOfKeyField>
<keyField Name=""/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain/>
<BusinessIdentifier/>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>YES</IsMessageProcessed>
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:cStat != ''">
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:cStat = '218'">101</xsl:when>
<xsl:otherwise><xsl:value-of select="nfe:retCancNFe/nfe:infCanc/nfe:cStat"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="retCancNFe/infCanc/cStat = '218'">101</xsl:when>
<xsl:otherwise><xsl:value-of select="retCancNFe/infCanc/cStat"/></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:xMotivo != ''">
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:cStat = '218'">Cancelamento de NF-e homologado</xsl:when>
<xsl:otherwise><xsl:value-of select="nfe:retCancNFe/nfe:infCanc/nfe:xMotivo"/></xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="retCancNFe/infCanc/cStat = '218'">Cancelamento de NF-e homologado</xsl:when>
<xsl:otherwise><xsl:value-of select="retCancNFe/infCanc/xMotivo"/></xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>chNFe</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:chNFe != ''">
<xsl:value-of select="nfe:retCancNFe/nfe:infCanc/nfe:chNFe"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retCancNFe/infCanc/chNFe"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:dhRecbto != ''">
<xsl:value-of select="nfe:retCancNFe/nfe:infCanc/nfe:dhRecbto"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retCancNFe/infCanc/dhRecbto"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:if test="nfe:retCancNFe/nfe:infCanc/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retCancNFe/nfe:infCanc/nfe:nProt != ''">
<xsl:value-of select="nfe:retCancNFe/nfe:infCanc/nfe:nProt"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retCancNFe/infCanc/nProt"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
</xsl:if>
</ListOfExtraInformation>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario2" userelativepaths="yes" externalpreview="no" url="file:///c:/Documents and Settings/neo31127/Desktop/canc3.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetCons_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber></TrackingNumber>
</TrackingId>
<Product>
<Name></Name>
<Version></Version>
</Product>
<Application></Application>
<Name></Name>
<Version></Version>
<Action></Action>
<ListOfKeyField>
<keyField Name=""/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain></Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>YES</IsMessageProcessed>
<!--Versão 2.00 -->
<xsl:choose>
<xsl:when test="boolean (/*[local-name()='retConsSitNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='cStat' and (namespace-uri()='' or namespace-uri()!='')])">
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:value-of select="/*[local-name()='retConsSitNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='cStat' and (namespace-uri()='' or namespace-uri()!='')]"/>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:value-of select="/*[local-name()='retConsSitNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='xMotivo' and (namespace-uri()='' or namespace-uri()!='')]"/>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>chNFe</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:chNFe!=''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:chNFe"/>
</xsl:when>
<xsl:when test="retConsSitNFe/chNFe!=''">
<xsl:value-of select="retConsSitNFe/chNFe"/>
</xsl:when>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:retCancNFe/nfe:infCanc/nfe:dhRecbto!=''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:retCancNFe/nfe:infCanc/nfe:dhRecbto"/>
</xsl:when>
<xsl:when test="retConsSitNFe/retCancNFe/infCanc/dhRecbto!=''">
<xsl:value-of select="retConsSitNFe/retCancNFe/infCanc/dhRecbto"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:dhRecbto != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:dhRecbto"/>
</xsl:when>
<xsl:when test="retConsSitNFe/protNFe/infProt/dhRecbto != ''">
<xsl:value-of select="retConsSitNFe/protNFe/infProt/dhRecbto"/>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:retCancNFe/nfe:infCanc/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="nfe:retConsSitNFe/nfe:retCancNFe/nfe:infCanc/nfe:nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/retCancNFe/infCanc/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="retConsSitNFe/retCancNFe/infCanc/nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/protNFe/infProt/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="retConsSitNFe/protNFe/infProt/nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value>
<xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:digVal"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/protNFe/infProt/digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value>
<xsl:value-of select="retConsSitNFe/protNFe/infProt/digVal"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</xsl:when>
<!--Versão 1.10 -->
<xsl:otherwise>
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:cStat != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:cStat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/infProt/cStat"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:xMotivo != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/infProt/xMotivo"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>chNFe</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:chNFe != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:chNFe"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/infProt/chNFe"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:dhRecbto != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:dhRecbto"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/infProt/dhRecbto"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/infProt/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="retConsSitNFe/infProt/nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:infProt/nfe:digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value>
<xsl:value-of select="nfe:retConsSitNFe/nfe:infProt/nfe:digVal"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/infProt/digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value>
<xsl:value-of select="retConsSitNFe/infProt/digVal"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</xsl:otherwise>
</xsl:choose>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="..\..\..\..\Users\bsoares\Desktop\retcons.xml" htmlbaseurl="..\..\..\ksm40386\Desktop\" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetEnv_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:NFe/nfe:infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:verAplic"/>
</verAplic>
<cStat>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo!=''">
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:NFe/nfe:infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:verAplic"/>
</verAplic>
<chNFe>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:chNFe"/>
</chNFe>
<dhRecbto>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:dhRecbto"/>
</dhRecbto>
<xsl:if test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:nProt != ''">
<nProt>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:nProt"/>
</nProt>
</xsl:if>
<xsl:if test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:digVal != ''">
<digVal>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/infProt/nfe:digVal"/>
</digVal>
</xsl:if>
<cStat>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo!=''">
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
<NFe>
<infNFe>
<ide>
<tpEmis>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:tpEmis"/>
</tpEmis>
<!--GRUPO SOMETE PARA VERSAO 2.00 -->
<xsl:if test="nfe:nfeProc/nfe:NFe/nfe:infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:if test="boolean(nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:dhCont)">
<dhCont>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:dhCont"/>
</dhCont>
</xsl:if>
<xsl:if test="boolean(nfeProc/NFe/infNFe/ide/dhCont)">
<dhCont>
<xsl:value-of select="nfeProc/NFe/infNFe/ide/dhCont"/>
</dhCont>
</xsl:if>
<xsl:if test="boolean(nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:xJust)">
<xJust>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:xJust"/>
</xJust>
</xsl:if>
<xsl:if test="boolean(nfeProc/NFe/infNFe/ide/xJust)">
<xJust>
<xsl:value-of select="nfeProc/NFe/infNFe/ide/xJust"/>
</xJust>
</xsl:if>
</xsl:if>
<!-- Final -->
</ide>
</infNFe>
</NFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="..\..\..\..\..\..\iReport-nb-3.6.0\iReport-nb-3.6.0\XML\procNFe.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetEnvError_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="NFe/infNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="NFe/infNFe/ide/tpAmb"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb"/>
</xsl:when>
</xsl:choose>
</tpAmb>
<verAplic>1.0</verAplic>
<cStat>999</cStat>
<xMotivo>Erro no aplicativo de transmissão NF-e</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="NFe/infNFe/ide/tpAmb"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb"/>
</xsl:when>
</xsl:choose>
</tpAmb>
<verAplic>1.0</verAplic>
<chNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe/@Id != ''">
<xsl:value-of select="substring(NFe/infNFe/@Id,'4','44')"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/@Id != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/@Id"/>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice != ''">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(IntegratorException/originalMSGXML/DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/>
</xsl:otherwise>
</xsl:choose>
</chNFe>
<dhRecbto>
<ng:formatdate outformat="yyyy-MM-dd'T'hh:mm:ss"/>
</dhRecbto>
<cStat>999</cStat>
<xMotivo>Erro no aplicativo de transmissão NF-e</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
<NFe>
<infNFe>
<ide>
<tpEmis>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpEmis != ''">
<xsl:value-of select="NFe/infNFe/ide/tpEmis"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpEmis != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpEmis"/>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="IntegratorException/originalMSGXML/DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted"/>
</xsl:otherwise>
</xsl:choose>
</tpEmis>
</ide>
</infNFe>
</NFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Documents and Settings/neo40386/Desktop/XML/retNFeAuthorized_20070912123509428.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetInut_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/></DateTime>
<TrackingNumber></TrackingNumber>
</TrackingId>
<Product>
<Name></Name>
<Version></Version>
</Product>
<Name></Name>
<Version></Version>
<Action></Action>
<ListOfKeyField>
<keyField Name="0"/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain></Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>YES</IsMessageProcessed>
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:cStat != ''">
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:cStat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retInutNFe/infInut/cStat"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:xMotivo != ''">
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retInutNFe/infInut/xMotivo"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:cUF"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value><xsl:value-of select="retInutNFe/infInut/cUF"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:ano"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value><xsl:value-of select="retInutNFe/infInut/ano"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:CNPJ"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value><xsl:value-of select="retInutNFe/infInut/CNPJ"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:mod"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value><xsl:value-of select="retInutNFe/infInut/mod"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:serie"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value><xsl:value-of select="retInutNFe/infInut/serie"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nNFIni"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value><xsl:value-of select="retInutNFe/infInut/nNFIni"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nNFFin"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value><xsl:value-of select="retInutNFe/infInut/nNFFin"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:dhRecbto"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value><xsl:value-of select="retInutNFe/infInut/dhRecbto"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value><xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nProt"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value><xsl:value-of select="retInutNFe/infInut/nProt"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario2" userelativepaths="yes" externalpreview="no" url="file:///c:/NF-e/queues/retInutNFe.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005a_RetProt_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="protNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="protNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:value-of select="protNFe/infProt/tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="protNFe/infProt/verAplic"/>
</verAplic>
<cStat>
<xsl:value-of select="protNFe/infProt/cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="protNFe/infProt/xMotivo!=''">
<xsl:value-of select="protNFe/infProt/xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="protNFe/infProt/cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="protNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="protNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:value-of select="protNFe/infProt/tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="protNFe/infProt/verAplic"/>
</verAplic>
<chNFe>
<xsl:value-of select="protNFe/infProt/chNFe"/>
</chNFe>
<dhRecbto>
<xsl:value-of select="protNFe/infProt/dhRecbto"/>
</dhRecbto>
<xsl:if test="protNFe/infProt/nProt != ''">
<nProt>
<xsl:value-of select="protNFe/infProt/nProt"/>
</nProt>
</xsl:if>
<xsl:if test="protNFe/infProt/digVal != ''">
<digVal>
<xsl:value-of select="protNFe/infProt/digVal"/>
</digVal>
</xsl:if>
<cStat>
<xsl:value-of select="protNFe/infProt/cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="protNFe/infProt/xMotivo!=''">
<xsl:value-of select="protNFe/infProt/xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="protNFe/infProt/cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="42070451421832000970550020000001230000001237.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NF005a_RetReceb_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/></DateTime>
<TrackingNumber>
<ng:counter name="EAITrackingNumber" format="0000000"/>
</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>InvoiceNFeRec</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<xsl:copy>
<xsl:choose>
<xsl:when test="boolean(nfe:nfeProc)">
<xsl:apply-templates select="nfe:nfeProc/nfe:NFe"/>
</xsl:when>
<xsl:when test="boolean(nfeProc/nfe:NFe)">
<xsl:apply-templates select="nfeProc/nfe:NFe"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="nfeProc/NFe"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="boolean(nfe:nfeProc)">
<xsl:apply-templates select="nfe:nfeProc/nfe:protNFe"/>
</xsl:when>
<xsl:when test="boolean(nfeProc/nfe:protNFe)">
<xsl:apply-templates select="nfeProc/nfe:protNFe"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="nfeProc/protNFe"/>
</xsl:otherwise>
</xsl:choose>
</xsl:copy>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Documents and Settings/neo40386/Desktop/XML/retNFeAuthorized_20070912123509428.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe005aCISA_Env_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<ng:setVariable name="NumSeg">0</ng:setVariable>
<ng:setVariable name="vOutro">0</ng:setVariable>
<ng:setVariable name="ObsCisa">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Narrative)"/>
</ng:setVariable>
<infNFe>
<xsl:attribute name="versao">1.10</xsl:attribute>
<xsl:attribute name="Id">NFe<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/></xsl:attribute>
<ide>
<cUF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteStateId"/>
</cUF>
<cNF>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'35','9')"/>
</cNF>
<natOp>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/FiscalOperation/FiscalOperationDescription"/>
</natOp>
<indPag>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '2'">0</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '3'">2</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</indPag>
<mod>55</mod>
<xsl:variable name="serie" select="number(normalize-space(DatasulMessage/BusinessContent/Upsert/DocumentSeries))"/>
<serie>
<xsl:choose>
<xsl:when test="string-length($serie) > 3">
<xsl:value-of select="substring($serie, '1', '3')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$serie"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNF>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/DocumentNumber)"/>
</nNF>
<dEmi>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/PrintDate"/>
</dEmi>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate!=''">
<dSaiEnt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate"/>
</dSaiEnt>
</xsl:if>
<tpNF>1</tpNF>
<cMunFG>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMunFG>
<tpImp>
<xsl:choose>
<xsl:when test="string-length(normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)) > 0">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpImp>
<tpEmis>
<xsl:variable name="iniSerial">900</xsl:variable>
<xsl:variable name="finSerial">999</xsl:variable>
<xsl:choose>
<xsl:when test="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted) = '2' ">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted)"/>
</xsl:when>
<!--<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentSeries >= $iniSerial and
DatasulMessage/BusinessContent/Upsert/DocumentSeries <= $finSerial ">3</xsl:when>-->
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpEmis>
<cDV>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'44','1')"/>
</cDV>
<tpAmb>1</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>5.0</verProc>
</ide>
<emit>
<CNPJ>
<xsl:value-of select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteTaxID,'.',''),'/',''),'-','')"/>
</CNPJ>
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteDescription"/>
</xNome>
<enderEmit>
<xsl:variable name="streetAddress" select="DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress"/>
<xsl:choose>
<xsl:when test="$streetAddress != ''">
<xLgr>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress"/>
</xLgr>
<nro>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteAddressNumber"/>
</nro>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement != ''">
<xCpl>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement"/>
</xCpl>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="nroEmit" select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,','))"/>
<xLgr>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,',')">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,','))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,','))"/>
</xsl:otherwise>
</xsl:choose>
</xLgr>
<nro>
<xsl:choose>
<xsl:when test="contains($nroEmit,',')">
<xsl:value-of select="substring-before($nroEmit,',')"/>
</xsl:when>
<xsl:when test="string-length($nroEmit) > 0">
<xsl:value-of select="$nroEmit"/>
</xsl:when>
<xsl:otherwise>s/n</xsl:otherwise>
</xsl:choose>
</nro>
<xsl:if test="contains($nroEmit,',')">
<xCpl>
<xsl:value-of select="normalize-space(substring-after($nroEmit,','))"/>
</xCpl>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMun>
<xMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityName"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateCode,$minusculas,$maiusculas)"/>
</UF>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryName != ''">
<xPais>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryName"/>
</xPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber!=''">
<fone>
<xsl:variable name="Fone">
<xsl:value-of select="translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber,' ',''),'-','')"/>
</xsl:variable>
<xsl:value-of select="translate(translate(translate(translate(translate($Fone,'(',''),')',''),'.',''),',',''),'/','')"/>
</fone>
</xsl:if>
</enderEmit>
<IE>
<xsl:value-of select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID,'.',''),'/',''),'-','')"/>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID != ''">
<IEST>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID"/>
</IEST>
</xsl:if>
</emit>
<xsl:variable name="destId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="destcMun" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
<xsl:variable name="destUF" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode"/>
<xsl:variable name="destBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName='' and $destcMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<ng:setVariable name="destA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="address">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$address != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="destN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressSupplement"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="nro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($nro,',')">
<ng:setVariable name="destN">
<xsl:value-of select="substring-before($nro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($nro) > 0">
<ng:setVariable name="destN">
<xsl:value-of select="$nro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="normalize-space(substring-after($nro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="destAddress">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:variable name="destNro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:variable name="destCpl">
<ng:getVariable name="destC"/>
</xsl:variable>
<dest>
<xsl:choose>
<xsl:when test="string-length($destId) = 11">
<CPF>
<xsl:value-of select="$destId"/>
</CPF>
</xsl:when>
<xsl:when test="$destcMun = '9999999'">
<CNPJ>
</CNPJ>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$destId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerName"/>
</xNome>
<enderDest>
<xLgr>
<xsl:value-of select="$destAddress"/>
</xLgr>
<nro>
<xsl:value-of select="$destNro"/>
</nro>
<xsl:if test="$destCpl != ''">
<xCpl>
<xsl:value-of select="$destCpl"/>
</xCpl>
</xsl:if>
<xBairro>
<xsl:choose>
<xsl:when test="$destBairro != ''">
<xsl:value-of select="$destBairro"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId = '9999999'">
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>EXTERIOR</xMun>
<UF>EX</UF>
</xsl:when>
<xsl:otherwise>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityName"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas)"/>
</UF>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName != ''">
<xPais>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName"/>
</xPais>
</xsl:if>
</enderDest>
<IE>
<xsl:value-of select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID,'.',''),'/',''),'-','')"/>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode != ''">
<ISUF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode"/>
</ISUF>
</xsl:if>
</dest>
<xsl:variable name="entregaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/LocationTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="entregacMun" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
<xsl:variable name="entregaUF" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode"/>
<xsl:variable name="entregaBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName='' and $entregacMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<ng:setVariable name="entregaA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="eAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$eAddress != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="entregaN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaC">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressSupplement"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="eNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($eNro,',')">
<ng:setVariable name="entregaN">
<xsl:value-of select="substring-before($eNro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($eNro) > 0">
<ng:setVariable name="entregaN">
<xsl:value-of select="$eNro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaC">
<xsl:value-of select="normalize-space(substring-after($eNro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="entregaAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:variable name="entregaNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:variable name="entregaCpl">
<ng:getVariable name="entregaC"/>
</xsl:variable>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation != '' and string-length($entregaId) = 14 and ($entregaId != $destId or $destAddress != $entregaAddress or $destNro != $entregaNro or $destCpl != $entregaCpl or $destBairro != $entregaBairro or $destcMun != $entregacMun or $destUF != $entregaUF )">
<entrega>
<CNPJ>
<xsl:value-of select="$entregaId"/>
</CNPJ>
<xsl:variable name="nroEntrega" select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
<xLgr>
<xsl:value-of select="$entregaAddress"/>
</xLgr>
<nro>
<xsl:value-of select="$entregaNro"/>
</nro>
<xsl:if test="$entregaCpl != ''">
<xCpl>
<xsl:value-of select="$entregaCpl"/>
</xCpl>
</xsl:if>
<xBairro>
<xsl:choose>
<xsl:when test="$entregaBairro != ''">
<xsl:value-of select="$entregaBairro"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityName"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas)"/>
</UF>
</entrega>
</xsl:if>
<ng:setVariable name="totalQtd">0</ng:setVariable>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentItens/DocumentItem">
<xsl:variable name="value">
<ng:getVariable name="vOutro"/>
</xsl:variable>
<xsl:variable name="expensesValue">
<xsl:value-of select="ItemValuesAndTaxes/ExpensesValue"/>
</xsl:variable>
<ng:setVariable name="vOutro">
<xsl:value-of select="$value + $expensesValue"/>
</ng:setVariable>
<xsl:variable name="cont">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<ng:setVariable name="NumSeg">
<xsl:value-of select="$cont + 1"/>
</ng:setVariable>
<xsl:variable name="qtd">
<xsl:value-of select="InvoicedQuantity"/>
</xsl:variable>
<xsl:variable name="totalQtd1">
<ng:getVariable name="totalQtd"/>
</xsl:variable>
<ng:setVariable name="totalQtd">
<xsl:value-of select="$totalQtd1 + $qtd"/>
</ng:setVariable>
<det>
<xsl:attribute name="nItem">
<xsl:variable name="conta">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<xsl:value-of select="$conta"/>
</xsl:attribute>
<prod>
<cProd>
<xsl:choose>
<xsl:when test="Item/ItemCode != ''">
<xsl:value-of select="Item/ItemCode"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
<xsl:otherwise>1101</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</cProd>
<cEAN>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEAN>
<xProd>
<xsl:value-of select="Item/ItemDescription"/>
</xProd>
<xsl:if test="FiscalClassification/FiscalClassificationID != ''">
<NCM>
<xsl:value-of select="format-number(FiscalClassification/FiscalClassificationID,'00000000')"/>
</NCM>
</xsl:if>
<CFOP>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
<xsl:otherwise>1101</xsl:otherwise>
</xsl:choose>
</CFOP>
<uCom>
<xsl:value-of select="UnitOfMeasure/UnitOfMeasureCode"/>
</uCom>
<qCom>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qCom>
<vUnCom>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnCom>
<vProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/TotalPrice,'0.00')"/>
</vProd>
<cEANTrib>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEANTrib>
<uTrib>
<xsl:choose>
<xsl:when test="CustomerUnitOfMeasure/UnitOfMeasureCode != ''">
<xsl:value-of select="CustomerUnitOfMeasure/UnitOfMeasureCode"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</uTrib>
<qTrib>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qTrib>
<vUnTrib>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnTrib>
<xsl:if test="ItemValuesAndTaxes/FreightValue != '' and ItemValuesAndTaxes/FreightValue != '0'">
<vFrete>
<xsl:value-of select="format-number(ItemValuesAndTaxes/FreightValue,'0.00')"/>
</vFrete>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/DiscountsAndBonifications/DiscountValue != '' and ItemValuesAndTaxes/DiscountsAndBonifications/DiscountValue != '0'">
<vDesc>
<xsl:value-of select="format-number(ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount,'0.00')"/>
</vDesc>
</xsl:if>
</prod>
<imposto>
<ICMS>
<xsl:choose>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '10'">
<ICMS10>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS10>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '20'">
<ICMS20>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS20>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '30'">
<ICMS30>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS30>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '40' or substring(StatusTaxIcms,'2','2') = '41' or substring(StatusTaxIcms,'2','2') = '50'">
<ICMS40>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
</ICMS40>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '51'">
<ICMS51>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS51>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '60'">
<ICMS60>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS60>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '70'">
<ICMS70>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS70>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '90'">
<ICMS90>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
</xsl:choose>
</pRedBC>
</xsl:if>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS90>
</xsl:when>
<xsl:otherwise>
<ICMS00>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:choose>
<xsl:when test="string-length(StatusTaxIcms) = 3">
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</xsl:when>
<xsl:otherwise>00</xsl:otherwise>
</xsl:choose>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS00>
</xsl:otherwise>
</xsl:choose>
</ICMS>
<xsl:if test="StatusTaxIpi != ''">
<IPI>
<cEnq>999</cEnq>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '01' or StatusTaxIpi = '02' or StatusTaxIpi = '03' or StatusTaxIpi = '04' or StatusTaxIpi = '05' or StatusTaxIpi = '51' or StatusTaxIpi = '52' or StatusTaxIpi = '53' or StatusTaxIpi = '54' or StatusTaxIpi = '55'">
<IPINT>
<CST>
<xsl:value-of select="StatusTaxIpi"/>
</CST>
</IPINT>
</xsl:when>
<xsl:otherwise>
<IPITrib>
<CST>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '00' or StatusTaxIpi = '49' or StatusTaxIpi = '50' or StatusTaxIpi = '99'">
<xsl:value-of select="StatusTaxIpi"/>
</xsl:when>
<xsl:otherwise>99</xsl:otherwise>
</xsl:choose>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pIPI>
<vIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
</IPITrib>
</xsl:otherwise>
</xsl:choose>
</IPI>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue!=''">
<II>
<vBC>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxCalculationBasis,'0.00')"/>
</vBC>
<vDespAdu>0</vDespAdu>
<vII>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue,'0.00')"/>
</vII>
<vIOF>0</vIOF>
</II>
</xsl:if>
<PIS>
<xsl:choose>
<xsl:when test="StatusTaxPis = '01' or StatusTaxPis = '02'">
<PISAliq>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISAliq>
</xsl:when>
<xsl:when test="StatusTaxPis = '03'">
<PISQtde>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISQtde>
</xsl:when>
<xsl:when test="StatusTaxPis = '04' or StatusTaxPis = '06' or StatusTaxPis = '07' or StatusTaxPis = '08' or StatusTaxPis = '09'">
<PISNT>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
</PISNT>
</xsl:when>
<xsl:otherwise>
<PISOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
</xsl:otherwise>
</xsl:choose>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISOutr>
</xsl:otherwise>
</xsl:choose>
</PIS>
<COFINS>
<xsl:choose>
<xsl:when test="StatusTaxPis = '01' or StatusTaxPis = '02'">
<COFINSAliq>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0.00</xsl:otherwise>
</xsl:choose>
</pCOFINS>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSAliq>
</xsl:when>
<xsl:when test="StatusTaxPis = '03'">
<COFINSQtde>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSQtde>
</xsl:when>
<xsl:when test="StatusTaxPis = '04' or StatusTaxPis = '06' or StatusTaxPis = '07' or StatusTaxPis = '08' or StatusTaxPis = '09'">
<COFINSNT>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
</COFINSNT>
</xsl:when>
<xsl:otherwise>
<COFINSOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pCOFINS>
</xsl:otherwise>
</xsl:choose>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSOutr>
</xsl:otherwise>
</xsl:choose>
</COFINS>
</imposto>
<xsl:if test="normalize-space(Narrative) != ''">
<infAdProd>
<xsl:choose>
<xsl:when test="string-length(normalize-space(Narrative)) > 500">Vide observacao da nota<xsl:variable name="ObsTemp">
<ng:getVariable name="ObsCisa"/>
</xsl:variable>
<ng:setVariable name="ObsCisa">
<xsl:value-of select="concat($ObsTemp,' Observacao do Item ',Item/ItemCode,': ',normalize-space(Narrative))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(Narrative)"/>
</xsl:otherwise>
</xsl:choose>
</infAdProd>
</xsl:if>
</det>
</xsl:for-each>
<total>
<ICMSTot>
<vBC>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<vICMS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<vBCST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vST>
<vProd>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vProd>
<vFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vFrete>
<vSeg>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vSeg>
<vDesc>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vDesc>
<vII>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vII>
<vIPI>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
<vPIS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
<vCOFINS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
<vOutro>
<xsl:variable name="value">
<ng:getVariable name="vOutro"/>
</xsl:variable>
<xsl:value-of select="format-number($value,'0.00')"/>
</vOutro>
<vNF>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Shipment/PaidFreightCity = '1'">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</modFrete>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID != ''">
<transporta>
<xsl:variable name="transportaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID,'.',''),'/',''),'-','')"/>
<xsl:choose>
<xsl:when test="string-length($transportaId) = 11">
<CPF>
<xsl:value-of select="$transportaId"/>
</CPF>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$transportaId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName != ''">
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName"/>
</xNome>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName = '' and DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName != ''">
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName"/>
</xNome>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID != ''">
<IE>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID"/>
</IE>
</xsl:if>
<xsl:variable name="street" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StreetAddress"/>
<xsl:if test="$street != ''">
<xsl:variable name="number" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressNumber"/>
<xsl:variable name="supplement" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressSupplement"/>
<xEnder>
<xsl:value-of select="normalize-space(substring(concat($street,' ',$number,' ',$supplement),'1','60'))"/>
</xEnder>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName != ''">
<xMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName"/>
</xMun>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode != ''">
<UF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode"/>
</UF>
</xsl:if>
</transporta>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateID != '' and DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateStateID != ''">
<veicTransp>
<placa>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateID"/>
</placa>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="translate(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateStateID,$minusculas,$maiusculas)"/>
</UF>
</veicTransp>
</xsl:if>
<xsl:variable name="pesoL" select="DatasulMessage/BusinessContent/Upsert/DocumentNetWeight"/>
<xsl:variable name="pesoB" select="DatasulMessage/BusinessContent/Upsert/DocumentGrossWeight"/>
<vol>
<qVol>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingQuantity != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingQuantity"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="qVol">
<ng:getVariable name="totalQtd"/>
</xsl:variable>
<xsl:value-of select="format-number($qVol,'0')"/>
</xsl:otherwise>
</xsl:choose>
</qVol>
<esp>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingDescription != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingDescription"/>
</xsl:when>
<xsl:otherwise>Unidade</xsl:otherwise>
</xsl:choose>
</esp>
<xsl:if test="$pesoL != ''">
<pesoL>
<xsl:value-of select="format-number($pesoL,'0.000')"/>
</pesoL>
</xsl:if>
<xsl:if test="$pesoB != ''">
<pesoB>
<xsl:value-of select="format-number($pesoB,'0.000')"/>
</pesoB>
</xsl:if>
</vol>
</transp>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills != ''">
<cobr>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills/DocumentBill">
<dup>
<nDup>
<xsl:value-of select="concat(BillNumber,'/',InstallmentNumber)"/>
</nDup>
<dVenc>
<xsl:value-of select="DueDate"/>
</dVenc>
<vDup>
<xsl:value-of select="translate(format-number(InstallmentNetValue,'0.00'),',','.')"/>
</vDup>
</dup>
</xsl:for-each>
</cobr>
</xsl:if>
<xsl:variable name="ObsCisa2">
<ng:getVariable name="ObsCisa"/>
</xsl:variable>
<xsl:if test="$ObsCisa2 != ''">
<infAdic>
<infCpl>
<xsl:value-of select="$ObsCisa2"/>
</infCpl>
</infAdic>
</xsl:if>
</infNFe>
</NFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2002 eXcelon Corp.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file://c:\Documents and Settings\neo40386\Desktop\DatasulMessage.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo srcSchemaPath="schemasDatasul\NF-e\InvoiceDocument_204_000.xsd" srcSchemaRoot="DatasulMessage" srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="schemasSEFAZ\enviNFe_v1.08.xsd" destSchemaRoot="enviNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/>
</metaInformation>
-->
NFe006c_Canc_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<cancNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/CancNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/CancNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/cancNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/cancNFe/@versao"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.07</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infCanc>
<xsl:choose>
<xsl:when test="boolean(DatasulMessage/BusinessContent/Upsert/CancNFe)">
<xsl:attribute name="Id">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/Id)"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>CANCELAR</xServ>
<chNFe>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/chNFe)"/>
</chNFe>
<nProt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/nProt"/>
</nProt>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Cancelamento: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/CancNFe/infCanc/xJust),'1','227')))"/>
</xJust>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="Id">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/Id)"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>CANCELAR</xServ>
<chNFe>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/chNFe)"/>
</chNFe>
<nProt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/nProt"/>
</nProt>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Cancelamento: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/cancNFe/infCanc/xJust),'1','227')))"/>
</xJust>
</xsl:otherwise>
</xsl:choose>
</infCanc>
</cancNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Users/bsoares/Desktop/New Folder (3)/xml-cancelamento-nota-nfe2.00.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="cancNFe_v1.06.xsd" destSchemaRoot="cancNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="CancelInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_Env_DatasulToSefaz.xsl
<?xml version='1.0' encoding='ISO-8859-1' ?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<NFe xmlns="http://www.portalfiscal.inf.br/nfe">
<ng:setVariable name="NumSeg">0</ng:setVariable>
<infNFe>
<xsl:attribute name="versao">1.10</xsl:attribute>
<xsl:attribute name="Id">NFe<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/></xsl:attribute>
<ide>
<cUF>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateId)"/>
</cUF>
<cNF>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'35','9')"/>
</cNF>
<natOp>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/FiscalOperation/FiscalOperationDescription),'1','60'))"/>
</natOp>
<indPag>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '2'">0</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/PaymentPlan/PaymentPlanDueCode = '3'">2</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</indPag>
<mod>55</mod>
<xsl:variable name="serie" select="number(normalize-space(DatasulMessage/BusinessContent/Upsert/DocumentSeries))"/>
<serie>
<xsl:choose>
<xsl:when test="string-length($serie) > 3">
<xsl:value-of select="substring($serie, '1', '3')"/>
</xsl:when>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/DocumentSeries) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$serie"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNF>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/DocumentNumber)"/>
</nNF>
<dEmi>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/PrintDate"/>
</dEmi>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate!=''">
<dSaiEnt>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/GoodsIssueDate"/>
</dSaiEnt>
</xsl:if>
<tpNF>
<xsl:variable name="FOCFOP" select="substring(DatasulMessage/BusinessContent/Upsert/ListOfDocumentItens/DocumentItem/FiscalOperation/FiscalOperationCFOP, '1', '1')"/>
<xsl:choose>
<xsl:when test="$FOCFOP = '1' or $FOCFOP = 2 or $FOCFOP = 3">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpNF>
<cMunFG>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMunFG>
<tpImp>
<xsl:choose>
<xsl:when test="string-length(normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)) > 0">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/DanfeFormat)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpImp>
<tpEmis>
<xsl:variable name="iniSerial">900</xsl:variable>
<xsl:variable name="finSerial">999</xsl:variable>
<xsl:variable name="tpEmis" select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted)"/>
<xsl:choose>
<xsl:when test="$tpEmis = '2' ">
<xsl:value-of select="$tpEmis"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</tpEmis>
<cDV>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice,'44','1')"/>
</cDV>
<tpAmb>1</tpAmb>
<finNFe>1</finNFe>
<procEmi>0</procEmi>
<verProc>5.0</verProc>
</ide>
<emit>
<CNPJ>
<xsl:value-of select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteTaxID,'.',''),'/',''),'-','')"/>
</CNPJ>
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteDescription),'1','60'))"/>
</xNome>
<enderEmit>
<xsl:variable name="streetAddress" select="DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress"/>
<xsl:choose>
<xsl:when test="$streetAddress != ''">
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStreetAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddressNumber),'1','60'))"/>
</nro>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement != ''">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddressSupplement),'1','60'))"/>
</xCpl>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="nroEmit" select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,','))"/>
<xLgr>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,',')">
<xsl:value-of select="normalize-space(substring(normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress,',')),'1','60'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteAddress),'1','60'))"/>
</xsl:otherwise>
</xsl:choose>
</xLgr>
<nro>
<xsl:choose>
<xsl:when test="contains($nroEmit,',')">
<xsl:value-of select="normalize-space(substring(normalize-space(substring-before($nroEmit,',')),'1','60'))"/>
</xsl:when>
<xsl:when test="string-length($nroEmit) > 0">
<xsl:value-of select="normalize-space(substring(normalize-space($nroEmit),'1','60'))"/>
</xsl:when>
<xsl:otherwise>s/n</xsl:otherwise>
</xsl:choose>
</nro>
<xsl:if test="contains($nroEmit,',')">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(substring-after($nroEmit,',')),'1','60'))"/>
</xCpl>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteDistrictName),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Site/SiteCityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateCode,$minusculas,$maiusculas))"/>
</UF>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Site/SiteZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryID != ''">
<cPais>1058</cPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCountryName != ''">
<xPais>Brasil</xPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber!=''">
<fone>
<xsl:variable name="Fone">
<xsl:value-of select="translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SitePhoneNumber,' ',''),'-','')"/>
</xsl:variable>
<xsl:variable name="EmitFone" select="translate(translate(translate(translate(translate($Fone,'(',''),')',''),'.',''),',',''),'/','')"/>
<xsl:choose>
<xsl:when test="substring($EmitFone,'1','1')='0'">
<xsl:value-of select="substring($EmitFone,'2','10')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($EmitFone,'1','10')"/>
</xsl:otherwise>
</xsl:choose>
</fone>
</xsl:if>
</enderEmit>
<IE>
<xsl:choose>
<xsl:when test="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID) = 'ISENTO'">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Site/SiteStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</xsl:otherwise>
</xsl:choose>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID != ''">
<IEST>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/TributarySubstituteStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</IEST>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID != '' or DatasulMessage/BusinessContent/Upsert/Site/SiteCNAEID != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID != ''">
<IM>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCityTaxID)"/>
</IM>
</xsl:when>
<xsl:otherwise>
<CNAE>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Site/SiteCNAEID)"/>
</CNAE>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</emit>
<xsl:variable name="destId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="destcMun" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
<xsl:variable name="destUF" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode)"/>
<xsl:variable name="destBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName='' and $destcMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<ng:setVariable name="destA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="address">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$address != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="destN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/AddressSupplement"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="nro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($nro,',')">
<ng:setVariable name="destN">
<xsl:value-of select="substring-before($nro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($nro) > 0">
<ng:setVariable name="destN">
<xsl:value-of select="$nro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="destN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="destC">
<xsl:value-of select="normalize-space(substring-after($nro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="destAddress">
<ng:getVariable name="destA"/>
</xsl:variable>
<xsl:variable name="destNro">
<ng:getVariable name="destN"/>
</xsl:variable>
<xsl:variable name="destCpl">
<ng:getVariable name="destC"/>
</xsl:variable>
<dest>
<xsl:choose>
<xsl:when test="string-length($destId) = 11">
<CPF>
<xsl:value-of select="$destId"/>
</CPF>
</xsl:when>
<xsl:when test="$destcMun = '9999999'">
<CNPJ>
</CNPJ>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$destId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerName),'1','60'))"/>
</xNome>
<enderDest>
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space($destAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space($destNro),'1','60'))"/>
</nro>
<xsl:if test="$destCpl != ''">
<xCpl>
<xsl:value-of select="normalize-space(substring(normalize-space($destCpl),'1','60'))"/>
</xCpl>
</xsl:if>
<xBairro>
<xsl:choose>
<xsl:when test="$destBairro != ''">
<xsl:value-of select="normalize-space(substring(normalize-space($destBairro),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId = '9999999'">
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>EXTERIOR</xMun>
<UF>EX</UF>
</xsl:when>
<xsl:otherwise>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas))"/>
</UF>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode != ''">
<CEP>
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/ZipCode,'00000000')"/>
</CEP>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CustomerCountryID != ''">
<cPais>
<xsl:value-of select="normalize-space(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CustomerCountryID))"/>
</cPais>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName != ''">
<xPais>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/CountryName),'1','60'))"/>
</xPais>
</xsl:if>
</enderDest>
<IE>
<xsl:choose>
<xsl:when test="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID) = 'ISENTO'">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/LocationStateTaxID,'.',''),'/',''),'-','')),'1','14'))"/>
</xsl:otherwise>
</xsl:choose>
</IE>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode != ''">
<ISUF>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/SUFRAMACode),'1','9'))"/>
</ISUF>
</xsl:if>
</dest>
<!-- A TAG DeliveryLocation é opcional, deve ser validado se foi enviado algum conteúdo nesta TAG antes de montar as informações -->
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation != ''">
<xsl:variable name="entregaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/LocationTaxID,'.',''),'/',''),'-','')"/>
<xsl:variable name="entregaIE" select="normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/LocationStateTaxID,'.',''),'/',''),'-',''))"/>
<xsl:variable name="entregacMun" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
<xsl:variable name="entregaUF" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode)"/>
<xsl:variable name="entregaBairro">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName='' and $entregacMun = '9999999'">Exterior</xsl:when>
<xsl:otherwise>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/DistrictName"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="destAddr" select="DatasulMessage/BusinessContent/Upsert/Customer/CustomerLocation/PhysicalAddress/Address"/>
<xsl:variable name="entregaAddr" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address"/>
<xsl:variable name="entregaCEP" select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/ZipCode)"/>
<xsl:variable name="entregaCpl" select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressSupplement"/>
<ng:setVariable name="entregaA">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StreetAddress"/>
</ng:setVariable>
<xsl:variable name="eAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$eAddress != ''">
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber != ''">
<ng:setVariable name="entregaN">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/AddressNumber"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,',')">
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(substring-before(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaA">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address)"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaN">
<xsl:value-of select="normalize-space(substring-after(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
</ng:setVariable>
<xsl:variable name="eNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="contains($eNro,',')">
<ng:setVariable name="entregaN">
<xsl:value-of select="substring-before($eNro,',')"/>
</ng:setVariable>
</xsl:when>
<xsl:when test="string-length($eNro) > 0">
<ng:setVariable name="entregaN">
<xsl:value-of select="$eNro"/>
</ng:setVariable>
</xsl:when>
<xsl:otherwise>
<ng:setVariable name="entregaN">s/n</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<ng:setVariable name="entregaCpl">
<xsl:value-of select="normalize-space(substring-after($eNro,','))"/>
</ng:setVariable>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="entregaAddress">
<ng:getVariable name="entregaA"/>
</xsl:variable>
<xsl:variable name="entregaNro">
<ng:getVariable name="entregaN"/>
</xsl:variable>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation != '' and ($entregaId != $destId or $destAddr != $entregaAddr)">
<entrega>
<xsl:choose>
<xsl:when test="$entregaUF = 'EX'">
<CNPJ>00000000000000</CNPJ>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="format-number($entregaId, '00000000000000')"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="nroEntrega" select="normalize-space(substring-after (DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/Address,','))"/>
<xLgr>
<xsl:value-of select="normalize-space(substring(normalize-space($entregaAddress),'1','60'))"/>
</xLgr>
<nro>
<xsl:value-of select="normalize-space(substring(normalize-space($entregaNro),'1','60'))"/>
</nro>
<xCpl>
<xsl:choose>
<xsl:when test="$entregaCpl != ''">
<xsl:value-of select="concat(normalize-space(substring(normalize-space($entregaCpl),'1','60')), ', IE: ', $entregaIE, ', CEP: ', $entregaCEP)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('nao informado, IE: ', $entregaIE, ', CEP: ', $entregaCEP)"/>
</xsl:otherwise>
</xsl:choose>
</xCpl>
<xBairro>
<xsl:choose>
<xsl:when test="$entregaBairro != ''">
<xsl:value-of select="normalize-space(substring(normalize-space($entregaBairro),'1','60'))"/>
</xsl:when>
<xsl:otherwise>Nao Informado</xsl:otherwise>
</xsl:choose>
</xBairro>
<cMun>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityId"/>
</cMun>
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space (DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:value-of select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Customer/DeliveryLocation/PhysicalAddress/StateCode,$minusculas,$maiusculas))"/>
</UF>
</entrega>
</xsl:if>
</xsl:if>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentItens/DocumentItem">
<xsl:variable name="cont">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<ng:setVariable name="NumSeg">
<xsl:value-of select="$cont + 1"/>
</ng:setVariable>
<det>
<xsl:attribute name="nItem">
<xsl:variable name="conta">
<ng:getVariable name="NumSeg"/>
</xsl:variable>
<xsl:value-of select="$conta"/>
</xsl:attribute>
<prod>
<cProd>
<xsl:choose>
<xsl:when test="Item/ItemCode != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(Item/ItemCode),'1','60'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</cProd>
<cEAN>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEAN>
<xProd>
<xsl:value-of select="normalize-space(substring(normalize-space(Item/ItemDescription),'1','120'))"/>
</xProd>
<xsl:if test="FiscalClassification/FiscalClassificationID != ''">
<NCM>
<xsl:value-of select="format-number(FiscalClassification/FiscalClassificationID,'00000000')"/>
</NCM>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/EX_TIPIID != ''">
<EXTIPI>
<xsl:value-of select="format-number(AdditionalInformationTaxes/EX_TIPIID,'000')"/>
</EXTIPI>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/Gender != ''">
<genero>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/Gender)"/>
</genero>
</xsl:if>
<CFOP>
<xsl:choose>
<xsl:when test="FiscalOperation/FiscalOperationCFOP != ''">
<xsl:value-of select="normalize-space(FiscalOperation/FiscalOperationCFOP)"/>
</xsl:when>
</xsl:choose>
</CFOP>
<uCom>
<xsl:value-of select="normalize-space(substring(normalize-space(UnitOfMeasure/UnitOfMeasureCode),'1','6'))"/>
</uCom>
<qCom>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qCom>
<vUnCom>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnCom>
<vProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/GoodsTotalValues/NetPrice,'0.00')"/>
</vProd>
<cEANTrib>
<xsl:value-of select="normalize-space(EANCode)"/>
</cEANTrib>
<uTrib>
<xsl:choose>
<xsl:when test="CustomerUnitOfMeasure/UnitOfMeasureCode != ''">
<xsl:value-of select="normalize-space(substring(normalize-space(CustomerUnitOfMeasure/UnitOfMeasureCode),'1','6'))"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</uTrib>
<qTrib>
<xsl:choose>
<xsl:when test="CustomerInvoicedQuantity != ''">
<xsl:value-of select="format-number(CustomerInvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qTrib>
<vUnTrib>
<xsl:value-of select="format-number(ItemValuesAndTaxes/UnitPriceValues/NetPrice,'0.0000')"/>
</vUnTrib>
<xsl:if test="ItemValuesAndTaxes/FreightValue != '' and ItemValuesAndTaxes/FreightValue != '0'">
<vFrete>
<xsl:value-of select="format-number(ItemValuesAndTaxes/FreightValue,'0.00')"/>
</vFrete>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount != '' and ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount != '0'">
<vDesc>
<xsl:value-of select="format-number(ItemValuesAndTaxes/DiscountsAndBonifications/DiscountAmount,'0.00')"/>
</vDesc>
</xsl:if>
<xsl:if test="ImportDocument/ImportDocumentNumber != ''">
<DI>
<nDI>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentNumber),'1','10'))"/>
</nDI>
<dDI>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentDate)"/>
</dDI>
<xLocDesemb>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentClearanceLocation),'1','60'))"/>
</xLocDesemb>
<UFDesemb>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentClearanceState)"/>
</UFDesemb>
<dDesemb>
<xsl:value-of select="normalize-space(ImportDocument/ImportDocumentClearanceDate)"/>
</dDesemb>
<cExportador>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocument/ImportDocumentExporterCode),'1','60'))"/>
</cExportador>
<xsl:for-each select="ImportDocument/ImportDocumentAdd">
<adi>
<nAdicao>
<xsl:value-of select="normalize-space(ImportDocumentAddNumber)"/>
</nAdicao>
<nSeqAdic>
<xsl:value-of select="normalize-space(ImportDocumentAddSequence)"/>
</nSeqAdic>
<cFabricante>
<xsl:value-of select="normalize-space(substring(normalize-space(ImportDocumentManufacturerID),'1','60'))"/>
</cFabricante>
<xsl:if test="ImportDocumentDiscount != ''">
<vDescDI>
<xsl:value-of select="normalize-space(ImportDocumentDiscount)"/>
</vDescDI>
</xsl:if>
</adi>
</xsl:for-each>
</DI>
</xsl:if>
<xsl:choose>
<xsl:when test="ItemVehicle/VehicleTypeOperation != ''">
<veicProd>
<tpOp>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleTypeOperation)"/>
</tpOp>
<chassi>
<xsl:value-of select="substring(ItemVehicle/VehicleID, '1', '17')"/>
</chassi>
<cCor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleColorID),'1','4'))"/>
</cCor>
<xCor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleColorName),'1','40'))"/>
</xCor>
<pot>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleMotorPower),'1','4'))"/>
</pot>
<CM3>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehiclePower),'1','4'))"/>
</CM3>
<pesoL>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleNetWeight),'1','9'))"/>
</pesoL>
<pesoB>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleGrossWeight),'1','9'))"/>
</pesoB>
<nSerie>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleSerialNumber),'1','9'))"/>
</nSerie>
<tpComb>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleFuel),'1','8'))"/>
</tpComb>
<nMotor>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleMotorNumber),'1','21'))"/>
</nMotor>
<CMKG>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleCMKG),'1','9'))"/>
</CMKG>
<dist>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleDistance),'1','4'))"/>
</dist>
<xsl:if test="ItemVehicle/VehicleRENAVAN != ''">
<RENAVAM>
<xsl:value-of select="normalize-space(substring(normalize-space(ItemVehicle/VehicleRENAVAN),'1','9'))"/>
</RENAVAM>
</xsl:if>
<anoMod>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleModelYear)"/>
</anoMod>
<anoFab>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleFabricatedYear)"/>
</anoFab>
<tpPint>
<xsl:value-of select="normalize-space(ItemVehicle/VehiclePaintID)"/>
</tpPint>
<tpVeic>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleType)"/>
</tpVeic>
<espVeic>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleEspecie)"/>
</espVeic>
<VIN>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleIdentificationNumber)"/>
</VIN>
<condVeic>
<xsl:choose>
<xsl:when test="ItemVehicle/VehicleCondition = 1 or ItemVehicle/VehicleCondition = 2 or ItemVehicle/VehicleCondition = 3">
<xsl:value-of select="normalize-space(ItemVehicle/VehicleCondition)"/>
</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</condVeic>
<cMod>
<xsl:value-of select="normalize-space(ItemVehicle/VehicleModel)"/>
</cMod>
</veicProd>
</xsl:when>
<xsl:when test="ItemMedicine/MedicineLotNumber != '' or ItemMedicine/MedicineQuantity != '' or ItemMedicine/MedicineFabricantedDate != '' or ItemMedicine/MedicineValidityDate != '' or ItemMedicine/MedicineMaxConsumerPrice != ''">
<xsl:for-each select="ItemMedicine">
<med>
<nLote>
<xsl:value-of select="normalize-space(MedicineLotNumber)"/>
</nLote>
<qLote>
<xsl:value-of select="normalize-space(format-number(MedicineQuantity,'0.000'))"/>
</qLote>
<dFab>
<xsl:value-of select="normalize-space(MedicineFabricatedDate)"/>
</dFab>
<dVal>
<xsl:value-of select="normalize-space(MedicineValidityDate)"/>
</dVal>
<vPMC>
<xsl:value-of select="normalize-space(format-number(MedicineMaxConsumerPrice,'0.00'))"/>
</vPMC>
</med>
</xsl:for-each>
</xsl:when>
<xsl:when test="ItemFuel/FuelID != ''">
<comb>
<xsl:if test="ItemFuel/FuelID != ''">
<cProdANP>
<xsl:value-of select="normalize-space(ItemFuel/FuelID)"/>
</cProdANP>
</xsl:if>
<xsl:if test="ItemFuel/FuelCODIF != ''">
<CODIF>
<xsl:value-of select="normalize-space(ItemFuel/FuelCODIF)"/>
</CODIF>
</xsl:if>
<xsl:if test="ItemFuel/FuelQuantity != ''">
<qTemp>
<xsl:value-of select="normalize-space(ItemFuel/FuelQuantity)"/>
</qTemp>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDECalculationBasis != '' or ItemFuel/FuelCIDEPercentage != '' or ItemFuel/FuelCIDEValue != ''">
<CIDE>
<xsl:if test="ItemFuel/FuelCIDECalculationBasis != ''">
<qBCProd>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDECalculationBasis,'0.0000'))"/>
</qBCProd>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDEPercentage != ''">
<vAliqProd>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDEPercentage,'0.0000'))"/>
</vAliqProd>
</xsl:if>
<xsl:if test="ItemFuel/FuelCIDEValue != ''">
<vCIDE>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelCIDEValue,'0.00'))"/>
</vCIDE>
</xsl:if>
</CIDE>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSCalculationBasis != '' or ItemFuel/FuelICMSValue != '' or ItemFuel/FuelICMSSubstitutionBasis != '' or ItemFuel/FuelICMSSubstitutionValue != ''">
<ICMSComb>
<xsl:if test="ItemFuel/FuelICMSCalculationBasis != ''">
<vBCICMS>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSCalculationBasis,'0.00'))"/>
</vBCICMS>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSValue != ''">
<vICMS>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSValue,'0.00'))"/>
</vICMS>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSSubstitutionBasis != ''">
<vBCICMSST>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSSubstitutionBasis,'0.00'))"/>
</vBCICMSST>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSSubstitutionValue != ''">
<vICMSST>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSSubstitutionValue,'0.00'))"/>
</vICMSST>
</xsl:if>
</ICMSComb>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionBasis != '' or ItemFuel/FuelICMSFateSubstitutionValue != ''">
<ICMSInter>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionBasis != ''">
<vBCICMSSTDest>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSFateSubstitutionBasis,'0.00'))"/>
</vBCICMSSTDest>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSFateSubstitutionValue != ''">
<vICMSSTDest>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSFateSubstitutionValue,'0.00'))"/>
</vICMSSTDest>
</xsl:if>
</ICMSInter>
</xsl:if>
<xsl:if test="ItemFuel/FuelICMSConsumSubstitutionBasis != '' or ItemFuel/FuelICMSConsumSubstitutionValue != '' or ItemFuel/FuelConsumptionStateID != ''">
<ICMSCons>
<vBCICMSSTCons>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSConsumSubstitutionBasis,'0.00'))"/>
</vBCICMSSTCons>
<vICMSSTCons>
<xsl:value-of select="normalize-space(format-number(ItemFuel/FuelICMSConsumSubstitutionValue,'0.00'))"/>
</vICMSSTCons>
<UFCons>
<xsl:value-of select="normalize-space(ItemFuel/FuelConsumptionStateID)"/>
</UFCons>
</ICMSCons>
</xsl:if>
</comb>
</xsl:when>
</xsl:choose>
</prod>
<imposto>
<ICMS>
<xsl:choose>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '10'">
<ICMS10>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS10>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '20'">
<ICMS20>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS20>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '30'">
<ICMS30>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS30>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '40' or substring(StatusTaxIcms,'2','2') = '41' or substring(StatusTaxIcms,'2','2') = '50'">
<ICMS40>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
</ICMS40>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '51'">
<ICMS51>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS51>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '60'">
<ICMS60>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS60>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '70'">
<ICMS70>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pRedBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS70>
</xsl:when>
<xsl:when test="substring(StatusTaxIcms,'2','2') = '90'">
<ICMS90>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</xsl:when>
</xsl:choose>
</pRedBC>
</xsl:if>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<modBCST>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsStModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '4'">3</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '5'">4</xsl:when>
<xsl:when test="CalculationBasisIcmsStModality = '6'">5</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBCST>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage != '0'">
<pRedBCST>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxReductionPercentage,'0.00')"/>
</pRedBCST>
</xsl:if>
<vBCST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<pICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxDiscountPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMSST>
<vICMSST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMSST>
</ICMS90>
</xsl:when>
<xsl:otherwise>
<ICMS00>
<orig>
<xsl:value-of select="substring(StatusTaxIcms,'1','1')"/>
</orig>
<CST>
<xsl:choose>
<xsl:when test="string-length(StatusTaxIcms) = 3">
<xsl:value-of select="substring(StatusTaxIcms,'2','2')"/>
</xsl:when>
<xsl:otherwise>00</xsl:otherwise>
</xsl:choose>
</CST>
<modBC>
<xsl:choose>
<xsl:when test="CalculationBasisIcmsModality = '2'">1</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '3'">2</xsl:when>
<xsl:when test="CalculationBasisIcmsModality = '4'">3</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</modBC>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pICMS>
<vICMS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue!='' and ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxationType != '3'">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
</ICMS00>
</xsl:otherwise>
</xsl:choose>
</ICMS>
<xsl:if test="StatusTaxIpi != ''">
<IPI>
<xsl:if test="AdditionalInformationTaxes/IPIFrameworkClass != ''">
<clEnq>
<xsl:value-of select="normalize-space(substring(normalize-space(AdditionalInformationTaxes/IPIFrameworkClass),'1','5'))"/>
</clEnq>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/ProducerTaxID != ''">
<CNPJProd>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/ProducerTaxID)"/>
</CNPJProd>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/IPISealID != ''">
<cSelo>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPISealID)"/>
</cSelo>
</xsl:if>
<xsl:if test="AdditionalInformationTaxes/IPISealQuantity != ''">
<qSelo>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPISealQuantity)"/>
</qSelo>
</xsl:if>
<xsl:choose>
<xsl:when test="AdditionalInformationTaxes/IPIFrameworkID != ''">
<cEnq>
<xsl:value-of select="normalize-space(AdditionalInformationTaxes/IPIFrameworkID)"/>
</cEnq>
</xsl:when>
<xsl:otherwise>
<cEnq>999</cEnq>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '01' or StatusTaxIpi = '02' or StatusTaxIpi = '03' or StatusTaxIpi = '04' or StatusTaxIpi = '05' or StatusTaxIpi = '51' or StatusTaxIpi = '52' or StatusTaxIpi = '53' or StatusTaxIpi = '54' or StatusTaxIpi = '55'">
<IPINT>
<CST>
<xsl:value-of select="StatusTaxIpi"/>
</CST>
</IPINT>
</xsl:when>
<xsl:otherwise>
<IPITrib>
<CST>
<xsl:choose>
<xsl:when test="StatusTaxIpi = '00' or StatusTaxIpi = '49' or StatusTaxIpi = '50' or StatusTaxIpi = '99'">
<xsl:value-of select="StatusTaxIpi"/>
</xsl:when>
<xsl:otherwise>99</xsl:otherwise>
</xsl:choose>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pIPI>
<vIPI>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue!=''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
</IPITrib>
</xsl:otherwise>
</xsl:choose>
</IPI>
</xsl:if>
<xsl:if test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue!=''">
<II>
<vBC>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxCalculationBasis,'0.00')"/>
</vBC>
<vDespAdu>0</vDespAdu>
<vII>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='II']/TaxValue,'0.00')"/>
</vII>
<vIOF>0</vIOF>
</II>
</xsl:if>
<PIS>
<xsl:choose>
<xsl:when test="StatusTaxPis = '01' or StatusTaxPis = '02'">
<PISAliq>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISAliq>
</xsl:when>
<xsl:when test="StatusTaxPis = '03'">
<PISQtde>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISQtde>
</xsl:when>
<xsl:when test="StatusTaxPis = '04' or StatusTaxPis = '06' or StatusTaxPis = '07' or StatusTaxPis = '08' or StatusTaxPis = '09'">
<PISNT>
<CST>
<xsl:value-of select="StatusTaxPis"/>
</CST>
</PISNT>
</xsl:when>
<xsl:otherwise>
<PISOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pPIS>
</xsl:otherwise>
</xsl:choose>
<vPIS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='PIS / PASEP']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
</PISOutr>
</xsl:otherwise>
</xsl:choose>
</PIS>
<COFINS>
<xsl:choose>
<xsl:when test="StatusTaxCofins = '01' or StatusTaxCofins = '02'">
<COFINSAliq>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0.00</xsl:otherwise>
</xsl:choose>
</pCOFINS>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSAliq>
</xsl:when>
<xsl:when test="StatusTaxCofins = '03'">
<COFINSQtde>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
<qBCProd>
<xsl:choose>
<xsl:when test="InvoicedQuantity != ''">
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</qBCProd>
<vAliqProd>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vAliqProd>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSQtde>
</xsl:when>
<xsl:when test="StatusTaxCofins = '04' or StatusTaxCofins = '06' or StatusTaxCofins = '07' or StatusTaxCofins = '08' or StatusTaxCofins = '09'">
<COFINSNT>
<CST>
<xsl:value-of select="StatusTaxCofins"/>
</CST>
</COFINSNT>
</xsl:when>
<xsl:otherwise>
<COFINSOutr>
<CST>99</CST>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue != ''">
<qBCProd>
<xsl:value-of select="format-number(InvoicedQuantity,'0.0000')"/>
</qBCProd>
<vAliqProd>
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxUnitaryValue,'0.0000')"/>
</vAliqProd>
</xsl:when>
<xsl:otherwise>
<vBC>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<pCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxPercentage,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</pCOFINS>
</xsl:otherwise>
</xsl:choose>
<vCOFINS>
<xsl:choose>
<xsl:when test="ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(ItemValuesAndTaxes/ListOfTaxes/DocumentItemTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
</COFINSOutr>
</xsl:otherwise>
</xsl:choose>
</COFINS>
</imposto>
<xsl:if test="normalize-space(Narrative) != ''">
<infAdProd>
<xsl:value-of select="normalize-space(substring(normalize-space(Narrative),'1','500'))"/>
</infAdProd>
</xsl:if>
</det>
</xsl:for-each>
<total>
<ICMSTot>
<vBC>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxCalculationBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBC>
<vICMS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vICMS>
<vBCST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionBasis,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vBCST>
<vST>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='ICMS']/TributarySubstitutionValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vST>
<vProd>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/GoodsValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vProd>
<vFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Freight/FreightValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vFrete>
<vSeg>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Insurance/InsuranceValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vSeg>
<vDesc>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DiscountsAndBonifications/TotalDiscountAmount,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vDesc>
<vII>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='II']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vII>
<vIPI>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='IPI']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vIPI>
<vPIS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='PIS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vPIS>
<vCOFINS>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/ListOfTaxes/DocumentTax[TaxDescription='COFINS']/TaxValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vCOFINS>
<vOutro>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Packaging/PackagingValue != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/Packaging/PackagingValue,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vOutro>
<vNF>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice != ''">
<xsl:value-of select="format-number(DatasulMessage/BusinessContent/Upsert/DocumentValuesAndTaxes/DocumentTotalPrice,'0.00')"/>
</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</vNF>
</ICMSTot>
</total>
<transp>
<modFrete>
<xsl:choose>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/Shipment/FreightType = '1'">0</xsl:when>
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</modFrete>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID!='' and string-length(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID)='11' or string-length(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID)='14'">
<transporta>
<xsl:variable name="transportaId" select="translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierTaxID,'.',''),'/',''),'-','')"/>
<xsl:choose>
<xsl:when test="string-length($transportaId) = 11">
<CPF>
<xsl:value-of select="$transportaId"/>
</CPF>
</xsl:when>
<xsl:otherwise>
<CNPJ>
<xsl:value-of select="$transportaId"/>
</CNPJ>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName != ''">
<xNome>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName),'1','60'))"/>
</xNome>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID != ''">
<IE>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierStateTaxID),'1','14'))"/>
</IE>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierFullName = '' and DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName != ''">
<xNome>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/CarrierName"/>
</xNome>
</xsl:if>
<xsl:variable name="street" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StreetAddress"/>
<xsl:if test="$street != ''">
<xsl:variable name="number" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressNumber"/>
<xsl:variable name="supplement" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/AddressSupplement"/>
<xEnder>
<xsl:value-of select="normalize-space(substring(concat($street,' ',$number,' ',$supplement),'1','60'))"/>
</xEnder>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName != ''">
<xMun>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/CityName),'1','60'))"/>
</xMun>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode != ''">
<UF>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="UFTransp" select="DatasulMessage/BusinessContent/Upsert/Shipment/CarrierInformation/PhysicalAddress/StateCode"/>
<xsl:value-of select="normalize-space(translate($UFTransp,$minusculas,$maiusculas))"/>
</UF>
</xsl:if>
</transporta>
</xsl:if>
<xsl:variable name="minusculas">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="maiusculas">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
<xsl:variable name="veicPlaca" select="substring(normalize-space(translate(translate(translate(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateID,'-',''),' ',''),$minusculas,$maiusculas)), '1', '8')"/>
<xsl:variable name="veicUF" select="normalize-space(translate(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/LicensePlateStateID,$minusculas,$maiusculas))"/>
<xsl:if test="$veicPlaca != '' and $veicUF != ''">
<veicTransp>
<placa>
<xsl:value-of select="$veicPlaca"/>
</placa>
<UF>
<xsl:value-of select="$veicUF"/>
</UF>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/RNTCID) != ''">
<RNTC>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/Shipment/LicensePlateOfTransportVehicle/RNTCID)"/>
</RNTC>
</xsl:if>
</veicTransp>
</xsl:if>
<xsl:variable name="qVol" select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingQuantity"/>
<xsl:variable name="esp" select="DatasulMessage/BusinessContent/Upsert/ListOfPackaging/Packaging/PackagingDescription"/>
<xsl:variable name="pesoL" select="DatasulMessage/BusinessContent/Upsert/DocumentNetWeight"/>
<xsl:variable name="pesoB" select="DatasulMessage/BusinessContent/Upsert/DocumentGrossWeight"/>
<xsl:if test="$qVol != '' or $esp != '' or $pesoL != '' or $pesoB != ''">
<vol>
<xsl:if test="$qVol != ''">
<qVol>
<xsl:value-of select="$qVol"/>
</qVol>
</xsl:if>
<xsl:if test="$esp != ''">
<esp>
<xsl:value-of select="normalize-space(substring(normalize-space($esp),'1','60'))"/>
</esp>
</xsl:if>
<xsl:if test="$pesoL != ''">
<pesoL>
<xsl:value-of select="format-number($pesoL,'0.000')"/>
</pesoL>
</xsl:if>
<xsl:if test="$pesoB != ''">
<pesoB>
<xsl:value-of select="format-number($pesoB,'0.000')"/>
</pesoB>
</xsl:if>
</vol>
</xsl:if>
</transp>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills != ''">
<cobr>
<xsl:for-each select="DatasulMessage/BusinessContent/Upsert/ListOfDocumentBills/DocumentBill">
<dup>
<nDup>
<xsl:value-of select="normalize-space(substring(normalize-space(concat(BillNumber,'/',InstallmentNumber)),'1','60'))"/>
</nDup>
<dVenc>
<xsl:value-of select="DueDate"/>
</dVenc>
<vDup>
<xsl:value-of select="translate(format-number(InstallmentNetValue,'0.00'),',','.')"/>
</vDup>
</dup>
</xsl:for-each>
</cobr>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Narrative != '' or DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation != ''">
<infAdic>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation) != ''">
<infAdFisco>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/AdditionalInformation)"/>
</infAdFisco>
</xsl:if>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/Narrative) != ''">
<infCpl>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Narrative),'1','5000'))"/>
</infCpl>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentID != ''">
<obsCont>
<xsl:attribute name="xCampo">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentID)"/>
</xsl:attribute>
<xTexto>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxPayerComment/TaxPayerCommentContent)"/>
</xTexto>
</obsCont>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentID != ''">
<obsFisco>
<xsl:attribute name="xCampo">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentID)"/>
</xsl:attribute>
<xTexto>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/TaxComment/TaxCommentContent)"/>
</xTexto>
</obsFisco>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessID != '' or DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessOriginID != ''">
<procRef>
<nProc>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessID),'1','60'))"/>
</nProc>
<indProc>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AdditionInformation/ReferencedProcess/ProcessOriginID)"/>
</indProc>
</procRef>
</xsl:if>
</infAdic>
</xsl:if>
<xsl:if test="normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointStateId) != '' and normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointDescription) != ''">
<exporta>
<UFEmbarq>
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointStateId)"/>
</UFEmbarq>
<xLocEmbarq>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/CountPointDescription),'1','60'))"/>
</xLocEmbarq>
</exporta>
</xsl:if>
<xsl:if test="DatasulMessage/BusinessContent/Upsert/Customer/CustomerOrderNumber != ''">
<compra>
<xPed>
<xsl:value-of select="normalize-space(substring(normalize-space(DatasulMessage/BusinessContent/Upsert/Customer/CustomerOrderNumber),'1','60'))"/>
</xPed>
</compra>
</xsl:if>
</infNFe>
</NFe>
</xsl:template>
</xsl:stylesheet>
<!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="no" externalpreview="no" url="file:///c:/Documents and Settings/mgoncalves/Desktop/Datasul/35185.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
--><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="teste\35185.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="schemasSEFAZ\enviNFe_v1.08.xsd" destSchemaRoot="enviNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="schemasDatasul\NF-e\InvoiceDocument_204_000.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_Env_DatasulToSefaz_InvoiceNFe.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://tempuri.com">
<xsl:template match="/">
<xsl:apply-templates select="/DatasulMessage/BusinessContent/Upsert/node()"/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="http://www.portalfiscal.inf.br/nfe">
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
NFe006c_Inut_DatasulToSefaz.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<inutNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/versao"/>
</xsl:attribute>
<infInut>
<xsl:attribute name="Id">
<xsl:value-of select="concat('ID',DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF,substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2'),DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ,DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod,format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie,'000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni,'000000000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin,'000000000'))"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xServ"/>
</xServ>
<cUF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF"/>
</cUF>
<ano>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2')"/>
</ano>
<CNPJ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ"/>
</CNPJ>
<mod>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod"/>
</mod>
<serie>
<xsl:choose>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie)"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNFIni>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni)"/>
</nNFIni>
<nNFFin>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin)"/>
</nNFFin>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Inutilizacao: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xJust),'1','227')))"/>
</xJust>
</infInut>
</inutNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="messages\Inut_0001166.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="..\Adapters\AD-Datasul\NF-e\SEFAZ\inutNFe_v1.06.xsd" destSchemaRoot="inutNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\Adapters\AD-Datasul\NF-e\Datasul\NF-e\InutInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_RetCanc_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<inutNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:attribute name="versao">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/versao"/>
</xsl:attribute>
<infInut>
<xsl:attribute name="Id">
<xsl:value-of select="concat('ID',DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF,substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2'),DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ,DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod,format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie,'000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni,'000000000'),format-number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin,'000000000'))"/>
</xsl:attribute>
<tpAmb>1</tpAmb>
<xServ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xServ"/>
</xServ>
<cUF>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/cUF"/>
</cUF>
<ano>
<xsl:value-of select="substring(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/ano,'3','2')"/>
</ano>
<CNPJ>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/CNPJ"/>
</CNPJ>
<mod>
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/mod"/>
</mod>
<serie>
<xsl:choose>
<xsl:when test="string-length(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie) = 0">0</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/serie)"/>
</xsl:otherwise>
</xsl:choose>
</serie>
<nNFIni>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFIni)"/>
</nNFIni>
<nNFFin>
<xsl:value-of select="number(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/nNFFin)"/>
</nNFFin>
<xJust>
<xsl:value-of select="normalize-space(concat('Justificativa Inutilizacao: ',substring(normalize-space(DatasulMessage/BusinessContent/Upsert/inutNFe/infInut/xJust),'1','227')))"/>
</xJust>
</infInut>
</inutNFe>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="messages\Inut_0001166.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="..\Adapters\AD-Datasul\NF-e\SEFAZ\inutNFe_v1.06.xsd" destSchemaRoot="inutNFe" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="..\Adapters\AD-Datasul\NF-e\Datasul\NF-e\InutInvoiceDocument_204_106.xsd" srcSchemaRoot="DatasulMessage" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_RetCons_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime><ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/></DateTime>
<TrackingNumber></TrackingNumber>
</TrackingId>
<Product>
<Name></Name>
<Version></Version>
</Product>
<Application></Application>
<Name></Name>
<Version></Version>
<Action></Action>
<ListOfKeyField>
<keyField Name=""/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain></Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>YES</IsMessageProcessed>
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:value-of select="/*[local-name()='retConsSitNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='cStat' and (namespace-uri()='' or namespace-uri()!='')]"/>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:value-of select="/*[local-name()='retConsSitNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='xMotivo' and (namespace-uri()='' or namespace-uri()!='')]"/>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>chNFe</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:chNFe != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:chNFe"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/protNFe/infProt/chNFe"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:dhRecbto != ''">
<xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:dhRecbto"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retConsSitNFe/protNFe/infProt/dhRecbto"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value><xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:nProt"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/protNFe/infProt/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value><xsl:value-of select="retConsSitNFe/protNFe/infProt/nProt"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value><xsl:value-of select="nfe:retConsSitNFe/nfe:protNFe/nfe:infProt/nfe:digVal"/></Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retConsSitNFe/protNFe/infProt/digVal != ''">
<ExtraInformation>
<Key>digVal</Key>
<Value><xsl:value-of select="retConsSitNFe/protNFe/infProt/digVal"/></Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/NF-e/queues/retConsSitNFe_3b.xml" htmlbaseurl="file:///c:/Documents and Settings/ksm40386/Desktop/" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_RetEnv_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/*[local-name()='nfeProc' and (namespace-uri()='' or namespace-uri()!='')]/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:NFe/nfe:infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:verAplic"/>
</verAplic>
<cStat>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo!=''">
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:NFe/nfe:infNFe[@versao > '2.00' or @versao = '2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:verAplic"/>
</verAplic>
<chNFe>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:chNFe"/>
</chNFe>
<dhRecbto>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:dhRecbto"/>
</dhRecbto>
<nProt>
<!-- MAP-1187 -->
<xsl:choose>
<xsl:when test="/*[local-name()='nfeProc' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='NFe' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='infNFe' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='infAdic' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='obsCont' and (namespace-uri() = '' or namespace-uri() != '')]/@xCampo = 'nRegDPEC' and nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat !='100'">
<xsl:value-of select="/*[local-name()='nfeProc' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='NFe' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='infNFe' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='infAdic' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='obsCont' and (namespace-uri() = '' or namespace-uri() != '')][@xCampo = 'nRegDPEC']/*[local-name()='xTexto' and (namespace-uri() = '' or namespace-uri() != '')]"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/*[local-name()='nfeProc' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='protNFe' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='infProt' and (namespace-uri() = '' or namespace-uri() != '')]/*[local-name()='nProt' and (namespace-uri() = '' or namespace-uri() != '')]"/>
</xsl:otherwise>
</xsl:choose>
<!-- MAP-1187 -->
</nProt>
<xsl:if test="/*[local-name()='nfeProc' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='protNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='infProt' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='digVal' and (namespace-uri()='' or namespace-uri()!='')] != ''">
<digVal>
<xsl:value-of select="/*[local-name()='nfeProc' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='protNFe' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='infProt' and (namespace-uri()='' or namespace-uri()!='')]/*[local-name()='digVal' and (namespace-uri()='' or namespace-uri()!='')]"/>
</digVal>
</xsl:if>
<cStat>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo!=''">
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="nfe:nfeProc/nfe:protNFe/nfe:infProt/nfe:cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
<NFe>
<infNFe>
<ide>
<tpEmis>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:tpEmis"/>
</tpEmis>
<xsl:if test="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:tpEmis !='1'">
<xsl:if test="boolean(nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:dhCont)">
<dhCont>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:dhCont"/>
</dhCont>
</xsl:if>
<xsl:if test="boolean(nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:xJust)">
<xJust>
<xsl:value-of select="nfe:nfeProc/nfe:NFe/nfe:infNFe/nfe:ide/nfe:xJust"/>
</xJust>
</xsl:if>
</xsl:if>
<xsl:if test="nfeProc/NFe/infNFe/ide/tpEmis !='1'">
<xsl:if test="boolean(nfeProc/NFe/infNFe/ide/dhCont)">
<dhCont>
<xsl:value-of select="nfeProc/NFe/infNFe/ide/dhCont"/>
</dhCont>
</xsl:if>
<xsl:if test="boolean(nfeProc/NFe/infNFe/ide/xJust)">
<xJust>
<xsl:value-of select="nfeProc/NFe/infNFe/ide/xJust"/>
</xJust>
</xsl:if>
</xsl:if>
</ide>
</infNFe>
</NFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="*"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="..\..\..\iReport-nb-3.6.0\iReport-nb-3.6.0\XML\procNFe.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006_RetEnvError_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng" version="1.0" extension-element-prefixes="ng" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="NFe/infNFe/ide/tpAmb"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb"/>
</xsl:when>
</xsl:choose>
</tpAmb>
<verAplic>1.0</verAplic>
<cStat>999</cStat>
<xMotivo>Erro no aplicativo de transmissão NF-e</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="NFe/infNFe/ide/tpAmb"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpAmb"/>
</xsl:when>
</xsl:choose>
</tpAmb>
<verAplic>1.0</verAplic>
<chNFe>
<xsl:choose>
<xsl:when test="NFe/infNFe/@Id != ''">
<xsl:value-of select="substring(NFe/infNFe/@Id,'4','44')"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/@Id != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/@Id"/>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice != ''">
<xsl:value-of select="normalize-space(DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="normalize-space(IntegratorException/originalMSGXML/DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/AcessKeyEletronicInvoice)"/>
</xsl:otherwise>
</xsl:choose>
</chNFe>
<dhRecbto>
<ng:formatdate outformat="yyyy-MM-dd'T'hh:mm:ss"/>
</dhRecbto>
<cStat>999</cStat>
<xMotivo>Erro no aplicativo de transmissão NF-e</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
<NFe>
<infNFe>
<ide>
<tpEmis>
<xsl:choose>
<xsl:when test="NFe/infNFe/ide/tpEmis != ''">
<xsl:value-of select="NFe/infNFe/ide/tpEmis"/>
</xsl:when>
<xsl:when test="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpEmis != ''">
<xsl:value-of select="IntegratorException/originalMSGXML/NFe/infNFe/ide/tpEmis"/>
</xsl:when>
<xsl:when test="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted != ''">
<xsl:value-of select="DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="IntegratorException/originalMSGXML/DatasulMessage/BusinessContent/Upsert/InvoiceEletronicDocument/KindPrinted"/>
</xsl:otherwise>
</xsl:choose>
</tpEmis>
</ide>
</infNFe>
</NFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="file:///c:/Documents and Settings/neo40386/Desktop/XML/retNFeAuthorized_20070912123509428.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_RetInut_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber></TrackingNumber>
</TrackingId>
<Product>
<Name></Name>
<Version></Version>
</Product>
<Name></Name>
<Version></Version>
<Action></Action>
<ListOfKeyField>
<keyField Name="0"/>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain></Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<ReturnContent>
<IsMessageProcessed>YES</IsMessageProcessed>
<xsl:choose>
<xsl:when test="boolean(/nfe:ProcInutNFe) or boolean(/ProcInutNFe)">
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:cStat != ''">
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:cStat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/cStat"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:xMotivo != ''">
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/xMotivo"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:cUF"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/cUF"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:ano"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/ano"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:CNPJ"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/CNPJ"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:mod"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/mod"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:serie"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/serie"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nNFIni"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/nNFIni"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nNFFin"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/nNFFin"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:dhRecbto"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/dhRecbto"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="/nfe:ProcInutNFe/nfe:retInutNFe/nfe:infInut/nfe:nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="/ProcInutNFe/retInutNFe/infInut/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="/ProcInutNFe/retInutNFe/infInut/nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</xsl:when>
<xsl:when test="boolean(/nfe:retInutNFe) or boolean(/retInutNFe)">
<ListOfExtraInformation>
<ExtraInformation>
<Key>cStat</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:cStat != ''">
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:cStat"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retInutNFe/infInut/cStat"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<ExtraInformation>
<Key>xMotivo</Key>
<Value>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:xMotivo != ''">
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="retInutNFe/infInut/xMotivo"/>
</xsl:otherwise>
</xsl:choose>
</Value>
</ExtraInformation>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:cUF"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/cUF != ''">
<ExtraInformation>
<Key>cUF</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/cUF"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:ano"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/ano != ''">
<ExtraInformation>
<Key>ano</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/ano"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:CNPJ"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/CNPJ != ''">
<ExtraInformation>
<Key>CNPJ</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/CNPJ"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:mod"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/mod != ''">
<ExtraInformation>
<Key>mod</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/mod"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:serie"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/serie != ''">
<ExtraInformation>
<Key>serie</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/serie"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nNFIni"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nNFIni != ''">
<ExtraInformation>
<Key>nNFIni</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/nNFIni"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nNFFin"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nNFFin != ''">
<ExtraInformation>
<Key>nNFFin</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/nNFFin"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:dhRecbto"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/dhRecbto != ''">
<ExtraInformation>
<Key>dhRecbto</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/dhRecbto"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
<xsl:choose>
<xsl:when test="nfe:retInutNFe/nfe:infInut/nfe:nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="nfe:retInutNFe/nfe:infInut/nfe:nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
<xsl:when test="retInutNFe/infInut/nProt != ''">
<ExtraInformation>
<Key>nProt</Key>
<Value>
<xsl:value-of select="retInutNFe/infInut/nProt"/>
</Value>
</ExtraInformation>
</xsl:when>
</xsl:choose>
</ListOfExtraInformation>
</xsl:when>
</xsl:choose>
</ReturnContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario2" userelativepaths="yes" externalpreview="no" url="file:///c:/NF-e/queues/retInutNFe.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasDatasul\NF-e\InutInvoiceRetDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="file://\\abrigo\APPS\goldmine2000\Attachments\45481\schemasSEFAZ\retInutNFe_v1.06.xsd" srcSchemaRoot="retInutNFe" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
NFe006c_RetProt_SefazToDatasul.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet exclude-result-prefixes="ng nfe" extension-element-prefixes="ng nfe" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ng="com.neogrid.integrator.XSLFunctions" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<DatasulMessage>
<Preamble>
<standardName>Datasul</standardName>
<standardVersion>200.000</standardVersion>
</Preamble>
<MessageHeader>
<TransactionId>
<TrackingId>
<DateTime>
<ng:formatdate outformat="yyyy-MM-dd'T'HH:mm:ss"/>
</DateTime>
<TrackingNumber>0</TrackingNumber>
</TrackingId>
<Product>
<Name>EMS2</Name>
<Version>204</Version>
</Product>
<Application>RECEIVER</Application>
<Name>ReturnInvoiceDocument</Name>
<Version>204.000</Version>
<Action>add</Action>
<ListOfKeyField>
<keyField>
<xsl:attribute name="Name">1</xsl:attribute>
</keyField>
</ListOfKeyField>
</TransactionId>
<CompanyId>
<Domain>CNPJ</Domain>
<BusinessIdentifier></BusinessIdentifier>
</CompanyId>
</MessageHeader>
<BusinessContent>
<Upsert>
<retConsReciNFe>
<xsl:choose>
<xsl:when test="protNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<tpAmb>
<xsl:value-of select="protNFe/infProt/tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="protNFe/infProt/verAplic"/>
</verAplic>
<cStat>
<xsl:value-of select="protNFe/infProt/cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="protNFe/infProt/xMotivo!=''">
<xsl:value-of select="protNFe/infProt/xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="protNFe/infProt/cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
<protNFe>
<xsl:choose>
<xsl:when test="protNFe[@versao='2.00']">
<xsl:attribute name="versao">2.00</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="versao">1.10</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<infProt>
<tpAmb>
<xsl:value-of select="protNFe/infProt/tpAmb"/>
</tpAmb>
<verAplic>
<xsl:value-of select="protNFe/infProt/verAplic"/>
</verAplic>
<chNFe>
<xsl:value-of select="protNFe/infProt/chNFe"/>
</chNFe>
<dhRecbto>
<xsl:value-of select="protNFe/infProt/dhRecbto"/>
</dhRecbto>
<xsl:if test="protNFe/infProt/nProt != ''">
<nProt>
<xsl:value-of select="protNFe/infProt/nProt"/>
</nProt>
</xsl:if>
<xsl:if test="protNFe/infProt/digVal != ''">
<digVal>
<xsl:value-of select="protNFe/infProt/digVal"/>
</digVal>
</xsl:if>
<cStat>
<xsl:value-of select="protNFe/infProt/cStat"/>
</cStat>
<xMotivo>
<xsl:choose>
<xsl:when test="protNFe/infProt/xMotivo!=''">
<xsl:value-of select="protNFe/infProt/xMotivo"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="protNFe/infProt/cStat"/>
</xsl:otherwise>
</xsl:choose>
</xMotivo>
</infProt>
</protNFe>
</retConsReciNFe>
</Upsert>
</BusinessContent>
</DatasulMessage>
</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="Scenario1" userelativepaths="yes" externalpreview="no" url="42070451421832000970550020000001230000001237.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="Datasul\NF-e\ReturnInvoiceDocument_204_106.xsd" destSchemaRoot="DatasulMessage" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no" ><SourceSchema srcSchemaPath="SEFAZ\procNFe_v1.08.xsd" srcSchemaRoot="nfeProc" AssociatedInstance="" loaderFunction="document" loaderFunctionUsesURI="no"/></MapperInfo><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->
RemoveNomeSpace.xsl
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Template de transformação responsável por remover todos os namespaces
do XML de entrada, gerando um XML de saída somente com elementos e atributos.
Autor(es): Luis Fernando da Silva
Marlo Eichenberg Motta
-->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="/|comment()|processing-instruction()">
<xsl:copy>
<xsl:apply-templates select="DatasulMessage"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>