xslt - Convert XML to string - XSL -
i have xml -
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:body> <fis:acctassnsvcrqst> <abcd/> <efgh/> </fis:acctassnsvcrqst> </soapenv:body> </soapenv:envelope>
i want output below
<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>
i want convert xml string , put in xsl , convert response string xml. tried multiple ways none of them worked.
using saxon 9.6 can use
<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>
to transform
<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>
into result
<?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>
Comments
Post a Comment