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

前端之家收集整理的这篇文章主要介绍了我可以向XSLT输出添加XML声明吗?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我当前的 XML输出

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

等等.我希望得到的输出如下:

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

我希望能够将第一行添加到我的输出中.在我的XSLT中,我试过& lt;

打印“<”但它被解释为& lt;.我也尝试了< xsl:text>,但遇到了同样的问题.有没有办法将这个声明行添加到我的XSLT?

解决方法

只需使用 xsl:output.

例…

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

猜你在找的XML相关文章