2013-02-10 14 views
22

Ciao sto generando un xml aggiungendo xsl a un input xml. Ho bisogno l'uscita senza questa parte "<?xml version="1.0" encoding="utf-16"?>"È necessario rimuovere <? Xml version = "1.0" encoding = "utf-16"?> Dall'xml

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

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

Uscita in corrente

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

Output previsto

<Entity>RIM_BPS</Entity> 
+2

Perché? Tutti i documenti XML validi devono iniziare con una dichiarazione XML. – SLaks

+0

@SLaks, sto indovinando un po 'erm non così soddisfacente e per essere franco implementazione povera. –

+2

@SLaks: la dichiarazione XML è facoltativa nei file XML tuttavia: [Suggerimento: utilizzare sempre una dichiarazione XML] (http://www.ibm.com/developerworks/xml/library/x-tipdecl/index.html) - (non è un * must * ma un * should *) – hakre

risposta

29

Prova ad aggiungere l'attributo omit-xml-declaration="yes" al tag xsl:output.

Dovrebbe quindi leggere in questo modo:

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

mettere questo nel vostro XSLT

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

o

ad una spinta estrema

<xsl:output method="text" /> 

dovrebbe risolvere il sintomo ...

L'ultimo potrebbe avere conseguenze significative a seconda del processore.

0

Questa trasformazione completa:

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

quando applicato sul documento XML fornito:

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

produce il desiderato, risultato corretto:

<Entity>RIM_BPS</Entity> 
3

Utilizzare questo XSLT per rimuovere encoding = "UTF-8" dal documento xml utilizzando XSLT.In sezione Cdaata È possibile aggiungere la codifica come desiderato. Saluti :)

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