Reputation: 13
I have a piece of xml file that has the following information:
<infAdic>
<infAdFisco>IMUNIDADE ICMS CONF. ART.155 DA CONST. FEDERAL-LUB. DERIVADO</infAdFisco>
<infCpl>
Preco sujeito alteracao. - O(s) produto(s) objeto(s) desta Nota Fiscal esta(ao) adequadamente acondicionado(s) para suportar os riscosnormais de carregamento, descarregamento, transbordo e transporte (Letra C do Item II, de Artigo 22, do Decreto N.96044/88)
<![CDATA[ <fabEntrega>Codi</fabEntrega>]]>
PO. number: Teste NFe 13122012
</infCpl>
<obsCont xCampo="DOCNUM">
<xTexto>0006703134</xTexto>
</obsCont>
<obsCont xCampo="emailDestinatarioNFe">
<xTexto>[email protected]</xTexto>
</obsCont>
<obsCont xCampo="idAplic">
<xTexto>LUBES</xTexto>
</obsCont>
</infAdic>
But when I execute the xml file above with xlst programa below
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:nfe="http://www.portalfiscal.inf.br/nfe">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="no" cdata-section-elements="nfe:infCpl"/>
<xsl:template match="/nfe:enviNFe">
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Header>
<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeRecepcao2">
<cUF>
<xsl:value-of select="nfe:NFe[1]/nfe:infNFe/nfe:ide/nfe:cUF"/>
</cUF>
<versaoDados>
<xsl:value-of select="@versao"/>
</versaoDados>
</nfeCabecMsg>
</soap12:Header>
<soap12:Body>
<nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeRecepcao2">
<enviNFe xmlns="http://www.portalfiscal.inf.br/nfe">
<xsl:attribute name="versao"><xsl:value-of select="@versao"/></xsl:attribute>
<xsl:copy-of select="nfe:idLote"/>
<xsl:for-each select="nfe:NFe">
<xsl:text disable-output-escaping="yes"><![CDATA[<NFe xmlns="http://www.portalfiscal.inf.br/nfe">]]></xsl:text>
<xsl:copy-of select="*"/>
<xsl:text disable-output-escaping="yes"><![CDATA[</NFe>]]></xsl:text>
</xsl:for-each>
</enviNFe>
</nfeDadosMsg>
</soap12:Body>
</soap12:Envelope>
</xsl:template>
</xsl:stylesheet>
I can not see the infCpl field with CDATA information. This is the result that I see:
<infCpl>
Preco sujeito alteracao. - O(s) produto(s) objeto(s) desta Nota Fiscal esta (ao) adequadamente acondicionado(s) para suportar os riscosnormais de carregamento, descarregamento, transbordo e transporte (Letra C do Item II, de Artigo 22, do Decreto N.96044/88)
<fabEntrega>Codi</fabEntrega>
PO. number: Teste NFe 13122012
</infCpl>
Could you help me because a I want the result below?
<infCpl>
Preco sujeito alteracao. - O(s) produto(s) objeto(s) desta Nota Fiscal esta(ao) adequadamente acondicionado(s) para suportar os riscosnormais de carregamento, descarregamento, transbordo e transporte (Letra C do Item II, de Artigo 22, do Decreto N.96044/88)
<![CDATA[ <fabEntrega>Codi</fabEntrega>]]>
PO. number: Teste NFe 13122012
</infCpl>
Regards, Sérgio Salomão
Upvotes: 1
Views: 522
Reputation: 163625
CDATA in XML is not designed to carry information. You shouldn't care about CDATA boundaries in your input. If you do care about them, then you need different tools - XSLT assumes that CDATA is just an authoring convenience, not a way of communicating information to the document recipient.
However, if you're stuck with processing XML in which CDATA has been abused in this way, then you might look at Andrew Welch's LexEv tool, which is bundled in KernowForSaxon.
Upvotes: 1
Reputation: 52888
If you know for sure that infCpl
will only contain CDATA and not mixed content (elements and CDATA), you can specify infCpl
as a cdata-section-element
in your xsl:output
<xsl:output indent="yes" cdata-section-elements="infCpl"/>
Example...
XML Input
<infAdic>
<infAdFisco>IMUNIDADE ICMS CONF. ART.155 DA CONST. FEDERAL-LUB. DERIVADO</infAdFisco>
<infCpl>
Preco & > < ' " sujeito alteracao. - O(s) produto(s) objeto(s) desta Nota Fiscal esta(ao) adequadamente acondicionado(s) para suportar os riscosnormais de carregamento, descarregamento, transbordo e transporte (Letra C do Item II, de Artigo 22, do Decreto N.96044/88)
<![CDATA[ <fabEntrega>Codi</fabEntrega>]]>
PO. number: Teste NFe 13122012
</infCpl>
<obsCont xCampo="DOCNUM">
<xTexto>0006703134</xTexto>
</obsCont>
<obsCont xCampo="emailDestinatarioNFe">
<xTexto>[email protected]</xTexto>
</obsCont>
<obsCont xCampo="idAplic">
<xTexto>LUBES</xTexto>
</obsCont>
</infAdic>
XSLT 2.0
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" cdata-section-elements="infCpl"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
XML Output
<infAdic>
<infAdFisco>IMUNIDADE ICMS CONF. ART.155 DA CONST. FEDERAL-LUB. DERIVADO</infAdFisco>
<infCpl><![CDATA[
Preco & > < ' " sujeito alteracao. - O(s) produto(s) objeto(s) desta Nota Fiscal esta(ao) adequadamente acondicionado(s) para suportar os riscosnormais de carregamento, descarregamento, transbordo e transporte (Letra C do Item II, de Artigo 22, do Decreto N.96044/88)
<fabEntrega>Codi</fabEntrega>
PO. number: Teste NFe 13122012
]]></infCpl>
<obsCont xCampo="DOCNUM">
<xTexto>0006703134</xTexto>
</obsCont>
<obsCont xCampo="emailDestinatarioNFe">
<xTexto>[email protected]</xTexto>
</obsCont>
<obsCont xCampo="idAplic">
<xTexto>LUBES</xTexto>
</obsCont>
</infAdic>
Upvotes: 1