I have a message
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://xmlns.oracle.com/policyautomation/hub/12.0/metadata/types">
<soapenv:Header/>
<soapenv:Body>
<load-request root="Vehicles" region="en-US" language="en-US" timezone="Etc/GMT">
<tables>
<table name="Vehicles">
<link name="Cars" target="Car" />
</table>
</tables>
</load-request>
</soapenv:Body>
and I need to make two transformations to it:
- remove SOAP Envelope
- transform the contents of the body (load-request tag)
I do know how to morph load-request, and tried this solution to remove SOAP, but cannot manage to combine the two and remove the envelope AND transform the body (load-request) with single xslt. The result XML should be:
<load-request>
<root>Vehicles</root>
<region>en-US</region>
<language>en-US</language>
<timezone>Etc/GMT</timezone>
<request-context>
<parameter>
<name>MyParam1</name>
<value>MyValue</value>
</parameter>
</request-context>
<tables>
<table>
<name>Vehicles</name>
<link>
<name>Cars</name>
<target>Car</target>
</link>
</table>
</tables>
</load-request>
The XSLT I used:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="soapenv:*">
<xsl:apply-templates select="@* | node()" />
</xsl:template>
<xsl:template match="load-request">
<xsl:element name="load-request">
<xsl:element name="root">
<xsl:value-of select="@root"/>
</xsl:element>
<xsl:element name="region">
<xsl:value-of select="@region"/>
</xsl:element>
<xsl:element name="language">
<xsl:value-of select="@language"/>
</xsl:element>
<xsl:element name="timezone">
<xsl:value-of select="@timezone"/>
</xsl:element>
<xsl:apply-templates select="request-context"/>
<xsl:apply-templates select="tables"/>
</xsl:element>
</xsl:template>
<xsl:template match="request-context">
<xsl:element name="request-context">
<xsl:for-each select="parameter">
<xsl:element name="parameter">
<xsl:element name="name">
<xsl:value-of select="@name"/>
</xsl:element>
<xsl:element name="value">
<xsl:value-of select="@value"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="tables">
<xsl:element name="tables">
<xsl:for-each select="table">
<xsl:element name="table">
<xsl:element name="name">
<xsl:value-of select="@name"/>
</xsl:element>
<xsl:apply-templates select="link"/>
<xsl:for-each select="field">
<xsl:element name="field">
<xsl:element name="name">
<xsl:value-of select="@name"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template match="link">
<xsl:element name="link">
<xsl:element name="name">
<xsl:value-of select="@name"/>
</xsl:element>
<xsl:element name="target">
<xsl:value-of select="@target"/>
</xsl:element>
</xsl:element>
</xsl:template>
<xsl:template match="field">
<xsl:for-each select="field">
<xsl:element name="field">
<xsl:element name="name">
<xsl:value-of select="@name"/>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Update: The answer works for the input. Could you please weigh in on additional tweak: In some of my scenarios turning attributes into elements is not enough. The message below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://xmlns.oracle.com/policyautomation/hub/12.0/metadata/types">
<soapenv:Header/>
<soapenv:Body>
<load-request root="Complains">
<field name="Explanation">
<text-val name="Text">The client needs a new toothbrush</text-val>
</field>
</load-request>
</soapenv:Body>
needs to become
<load-request>
<root>Complains</root>
<field>
<name>Explanation</name>
<text-val>
<name>Text</name>
<value>The client needs a new toothbrush</value>
</text-val>
</field>
</load-request>