我可以向XSLT输出添加XML声明吗?

时间:2021-02-27 14:05:50

Here is my current XML output:

这是我当前的XML输出:

    <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;

我希望能够将第一行添加到我的输出中。在我的XSLT中,我尝试过<

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?

打印“<”但它被解释为<。我也试过 ,但遇到了同样的问题。有没有办法将这个声明行添加到我的XSLT?

1 个解决方案

#1


5  

Just use xsl:output.

只需使用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>

#1


5  

Just use xsl:output.

只需使用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>