需要从 xml 中删除<?xml 版本= "1.0"编码= "utf-16" ?>


你好,我正在通过将xsl应用于xml输入来生成xml。我需要没有这个部件的输出"<?xml version="1.0" encoding="utf-16"?>"

输入——xml

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateResponse xmlns="http://jerseytelecom.com/">
    <CreateResult>
        <ISD_XMLGateway>
            <Entity>RIM_BPS</Entity>
         </ISD_XMLGateway>
    </CreateResult>
   </CreateResponse>
</soap:Body>
</soap:Envelope> 

我的xsl

    <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:JT="http://jerseytelecom.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="JT">
         <xsl:output method="xml" indent="yes"/>
         <xsl:template match="/">
           <xsl:element name="Entity">
            <xsl:value-of select="soap:Envelope/soap:Body/JT:CreateResponse/JT:CreateResult/JT:ISD_XMLGateway/JT:Entity"/>  
            </xsl:element>
            </xsl:template>
            </xsl:stylesheet>

电流输出

   <?xml version="1.0" encoding="utf-16"?>
    <Entity>RIM_BPS</Entity>

预期输出

    <Entity>RIM_BPS</Entity>

尝试将omit-xml-declaration="yes"属性添加到xsl:output标记中。

然后应该读成这样:

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

将其放入xslt

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

在极限推力下

<xsl:output method="text" />

应该解决症状。。。

最后一个可能会产生重大后果,尽管这取决于处理器。

使用此XSLT从使用XSLT的xml文档中删除encoding="UTF-8"。在Cdaata部分,您可以随意添加编码。干杯:(

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0"?>]]></xsl:text>
        <xsl:copy-of select="node()"/>
    </xsl:template>
</xsl:stylesheet>

此完整转换

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:JT="http://jerseytelecom.com/" exclude-result-prefixes="soap JT">
<xsl:output omit-xml-declaration="yes" indent="yes"
     encoding="utf-8"/>
 <xsl:template match="/">
  <Entity>
   <xsl:value-of select=
   "soap:Envelope/soap:Body/JT:CreateResponse
              /JT:CreateResult/JT:ISD_XMLGateway/JT:Entity"/>
  </Entity>
 </xsl:template>
</xsl:stylesheet>

应用于所提供的XML文档时:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
 xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateResponse xmlns="http://jerseytelecom.com/">
    <CreateResult>
        <ISD_XMLGateway>
            <Entity>RIM_BPS</Entity>
         </ISD_XMLGateway>
    </CreateResult>
   </CreateResponse>
</soap:Body>
</soap:Envelope>

生成所需的正确结果:

<Entity>RIM_BPS</Entity>

最新更新