2015-10-27 1 views
0

J'ai XML comme ça -Convertir XML à chaîne - XSL

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
     <fis:AcctAssnSvcRqst>  
      <abcd/> 
      <efgh/> 
     </fis:AcctAssnSvcRqst> 
    </soapenv:Body> 
</soapenv:Envelope> 

Je veux sortie comme ci-dessous

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gc="http://oracle.com/APIService.xsd"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <gc:APIService dateTimeTagFormat="xsd:strict"> 
      <gc:input> 
       <gc:SoapEnvelope> 
        <![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
         <soapenv:Body> 
          <fis:AcctAssnSvcRqst> 
           <abcd/> 
           <efgh/> 
          </fis:AcctAssnSvcRqst> 
         </soapenv:Body> 
        </soapenv:Envelope>]]> 
       </gc:SoapEnvelope> 
      </gc:input> 
     </gc:GC-FISAPIService> 
    </soapenv:Body> 
</soapenv:Envelope> 

Je veux convertir le XML en une chaîne et le mettre dans xsl et convertissez la réponse de String en XML. J'ai essayé plusieurs façons, mais aucune d'entre elles n'a fonctionné.

+0

bien où est 'SIF: AcctAssnSvcRqst' a déclaré faire bien l'espace de noms d'entrée format XML? En ce qui concerne la sérialisation de XML en chaîne, utilisez un processeur XSLT 3.0 comme Saxon 9.6 et la fonction http://www.w3.org/TR/xpath-functions-30/#func-serialize ou utilisez un autre processeur XSLT fournit la fonctionnalité en tant qu'extension. –

+0

J'ai édité l'original XML pour m'assurer que je ne donne aucune information confidentielle. J'ai raté cet espace de noms je pense. – raksrockz

Répondre

0

utilisant Saxon 9.6, vous pouvez utiliser

<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:gc="http://oracle.com/APIService.xsd" 
    exclude-result-prefixes="xs" 
    version="3.0"> 

<xsl:output method="xml" cdata-section-elements="gc:SoapEnvelope"/> 

<xsl:variable name="ser1"> 
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"> 
    <output:omit-xml-declaration value="yes"/> 
</output:serialization-parameters> 
</xsl:variable> 

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

<xsl:template match="soapenv:Envelope"> 
    <soapenv:Envelope> 
    <xsl:apply-templates/> 
    </soapenv:Envelope> 
</xsl:template> 

<xsl:template match="soapenv:Body"> 
    <xsl:copy> 
    <gc:APIService dateTimeTagFormat="xsd:strict"> 
     <gc:input> 
      <gc:SoapEnvelope> 
       <xsl:value-of select="serialize(/*, $ser1/*)"/> 
      </gc:SoapEnvelope> 
     </gc:input> 
    </gc:APIService> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 

pour transformer

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fis="http://example.com/fis"> 
    <soapenv:Body> 
     <fis:AcctAssnSvcRqst> 

      <abcd/> 
      <efgh/> 

     </fis:AcctAssnSvcRqst> 

    </soapenv:Body> 
</soapenv:Envelope> 

dans le résultat

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gc="http://oracle.com/APIService.xsd"> 
    <soapenv:Body xmlns:fis="http://example.com/fis"><gc:APIService dateTimeTagFormat="xsd:strict"><gc:input><gc:SoapEnvelope><![CDATA[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fis="http://example.com/fis"> 
    <soapenv:Body> 
     <fis:AcctAssnSvcRqst> 

      <abcd/> 
      <efgh/> 

     </fis:AcctAssnSvcRqst> 

    </soapenv:Body> 
</soapenv:Envelope>]]></gc:SoapEnvelope></gc:input></gc:APIService></soapenv:Body> 
</soapenv:Envelope>