Reputation: 11
I have used 2 xslt to generate the Output Expected but I am getting the Output where in child elements are clubbed and provided as a text .
So , Can you please let me know on
1) What can be added at in XSLT 2 to generate the required output . 2) Ways to combine 2 xslt and present it as a single xslt . 3) Better way of writing xslt to generate the output needed.
Details
Input
<?xml version="1.0" encoding="UTF-8"?>
<ns1:fnsetEngineReleased xmlns:ns1="http://from_sap.interfaces.oms"><ns1:strPO>DDDD</ns1:strPO><ns1:strEngine>ASAS</ns1:strEngine></ns1:fnsetEngineReleased>
Output Expected
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:from="http://from_sap.interfaces.oms">
<soap:Header/>
<soap:Body>
<from:fnsetEngineReleased>
<from:strPO>DDDD</from:strPO>
<from:strEngine>ASAS</from:strEngine>
</from:fnsetEngineReleased>
</soap:Body>
</soap:Envelope>
Output Obtained
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:from="http://from_sap.interfaces.oms">
<soap:Header/>
<soap:Body>
<from:fnsetEngineReleased>DDDDASAS</from:fnsetEngineReleased>
</soap:Body>
</soap:Envelope>
XSLT1 -Remove Namespace
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
XSLT2 -Add Namespace
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/*">
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:from="http://from_sap.interfaces.oms" >
<soap:Header></soap:Header>
<soap:Body>
<xsl:element name="from:{local-name()}" namespace="http://from_sap.interfaces.oms">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 847
Reputation: 2327
Both namespaces are the same. You do not need anything fancy, just copy the input to the output, all you want is wrapping it into a SOAP envelope:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
version="1.0">
<xsl:template match="/">
<soap:Envelope>
<soap:Header/>
<soap:Body>
<xsl:copy-of name="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1