I am able to remove parent node in XML but white spaces are still there and i see some hard code is also removed.
My XML
<?xml version="1.0" encoding="UTF-8"?>
<EDIDATA>
<MetaData>
<Sender>NCBK</Sender>
<MessageType>ABCDE</MessageType>
<TranType>INT</TranType>
<ValueDate>220427</ValueDate>
<CorpReferenceNumber>0000JF4HHwBHLcKD</CorpReferenceNumber>
<ExecutionDate>2204271029</ExecutionDate>
<AccountNumber>08563275789</AccountNumber>
<Status>OK</Status>
<DeliveryStatus>OK</DeliveryStatus>
<MessageDescription>Credit Notification</MessageDescription>
<SequenceNumber>220400100000305</SequenceNumber>
<TransactionReference>100000305</TransactionReference>
<ErrorDescription>-</ErrorDescription>
<Account>20817167000105</Account>
<TimeStamp>2022-04-27T10:28:01</TimeStamp>
</MetaData>
<Payload><![CDATA[]]></Payload>
</EDIDATA>
I am getting below output:
<?xml version="1.0" encoding="UTF-8"?>
<EDIDATA> **Getting space below EDIDATA:**
<Sender>NCBK</Sender>
<MessageType>CRNTF</MessageType>
<TranType>INT</TranType>
<ValueDate>220427</ValueDate>
<CorpReferenceNumber>8HplxF4HHwBHLcKD</CorpReferenceNumber>
<ExecutionDate>2204271029</ExecutionDate>
<AccountNumber>20817167000105</AccountNumber>
<Status>OK</Status>
<DeliveryStatus>OK</DeliveryStatus>
<MessageDescription>Credit Notification</MessageDescription>
<SequenceNumber>220427100000305</SequenceNumber>
<TransactionReference>100000305</TransactionReference>
<ErrorDescription>-</ErrorDescription>
<Account>20817167000105</Account>
<TimeStamp>2022-04-27T10:28:01</TimeStamp> **Getting space below TimeStamp:**
<Payload /> **Payload is empty after xslt**
</EDIDATA>
Using below xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="*">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:template>
<xsl:template match="MetaData">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
Can anyone suggest what needs to be corrected here:
CodePudding user response:
To remove the extra white space, you can add this instruction:
<xsl:strip-space elements="*"/>
to the top level of your stylesheet.
FYI, the Payload
element is empty in the original XML too. If you want Payload
to continue using CDATA for its text, you should change the xsl:output
instruction to:
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" cdata-section-elements="Payload"/>
but I doubt your processor will bother to implement it when there is no actual text.
P.S. I don't see why you need to use:
<xsl:element name="{local-name(.)}">
instead of:
<xsl:copy>