2

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>
2
  • 2
    Usually, if you run your XML through an XSLT stylesheet that declares <xsl:output omit-xml-declaration="yes"/> and the XSLT processor is in charge of serializing the result tree you shouldn't get an XML declaration in the result document. So you might need to explain to us in more detail which processor you use, how you use it exactly (show us the command line options you use or the exact programming code you have to run the XSLT transformation) to allow us to tell why the declaration appears in the result. Commented Mar 14, 2021 at 14:32
  • While asking a question you need to provide a minimal reproducible example: (1) Input XML. (2) Your logic, and XSLT that tried to implement it. (3) Desired output. (4) XSLT processor and its version. Commented Mar 14, 2021 at 17:46

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.