Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add an XML declaration to an XSLT output?

Tags:

xml

xslt

Here is my current XML output:

    <EmployeeImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Employee>
    <EmployeeNumber>123</EmployeeNumber>
    <FirstName>Jose</FirstName>
    </Employee>
    </EmployeeImport>

and so on. What I would like to have my output is the following:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <EmployeeImport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Employee>
    <EmployeeNumber>123</EmployeeNumber>
    <FirstName>Jose</FirstName>
    </Employee>
    </EmployeeImport>

I would like to be able to add the first line to my output. In my XSLT, I have tried &lt;

to print "<" but it is interpreted just as &lt;. I have also tried <xsl:text>, but ran into the same issue. Is there a way to add this declaratory line to my XSLT?

like image 910
Adam L Avatar asked Jan 29 '23 10:01

Adam L


1 Answers

Just use xsl:output.

Example...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output version="1.0" encoding="UTF-8" standalone="yes"/>

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

</xsl:stylesheet>
like image 136
Daniel Haley Avatar answered Feb 04 '23 02:02

Daniel Haley