How to remove extra xml declaration from xml file in XSLT?

Viewed 263

I have XML file with declaration and I need to remove it using XSLT for stylesheet version="2.0" I used <xsl:output method="xml" omit-xml-declaration="yes" /> but it did not work as I think it works with stylesheet version="1.0"

the xml file I have (input)

<?xml version="1.0" encoding="UTF-8"?>
<eExact>
<GLEntries>
    <GLEntry>
        <Description>Report 2020-08</Description>
        <Date>23-09-2020</Date>
        <DocumentDate>23-09-2020</DocumentDate>
        <Journal code="70"/>
        <FinEntryLine number="1">
            <GLAccount code="4590"/>
            <Creditor code="520094"/>
            <Description>Heidi Draaisma</Description>
            <Date>23-09-2020</Date>
            <Amount>
                <Currency code="EUR"/>
                <Debit>37.61</Debit>
            </Amount>
        </FinEntryLine>
    </GLEntry>
</GLEntries>
</eExact>

The output I need

<eExact>
<GLEntries>
    <GLEntry>
        <Description>Report 2020-08</Description>
        <Date>23-09-2020</Date>
        <DocumentDate>23-09-2020</DocumentDate>
        <Journal code="70"/>
        <FinEntryLine number="1">
            <GLAccount code="4590"/>
            <Creditor code="520094"/>
            <Description>Heidi Draaisma</Description>
            <Date>23-09-2020</Date>
            <Amount>
                <Currency code="EUR"/>
                <Debit>37.61</Debit>
            </Amount>
        </FinEntryLine>
    </GLEntry>
</GLEntries>
</eExact>
1 Answers

I have XML file with declaration and I need to remove it using XSLT for stylesheet version="2.0"

This is the transformation you want:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

Explanation:

  1. <xsl:output omit-xml-declaration="yes"/>

  2. The identity rule/template

Related