on 01-22-2015 5:40 PM
I have a no-soap scenario, where i need to handle the soap response and the soap fault using the same xslt/structure.
Either the SOAP response comes or the fault message comes.
I need to remove the soap envelope.
And accomodate both the messages using a single structure.
I do have the flexibility of changing the target hierarchy.
The response is like this
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope>
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<out6:struct1>
<struct2>
...
...
</struct2>
</out6:struct1>
<s/oapenv:Body>
</soapenv:Envelope>
My fault message is as follows
<soapenv:Envelope>
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
...
</soapenv:Fault>
<s/oapenv:Body>
</soapenv:Envelope>
Hi Priyadarshini ,
You have severals ways to do it depending of what structure you want to the output.
For example with this XSL:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope">
<xsl:output method="xml" encoding="utf-8" indent="no"/>
<xsl:template match="/">
<RootElement>
<xsl:if test="soapenv:Envelope/soapenv:Body">
<xsl:copy-of select="/soapenv:Envelope/soapenv:Body/child::*" />
</xsl:if>
<message_err>
<xsl:if test="/soapenv:Envelope/soapenv:Fault">
<xsl:value-of select="/soapenv:Envelope/soapenv:Fault" />
</xsl:if>
</message_err>
</RootElement>
</xsl:template>
</xsl:stylesheet>
If you have this XML:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope">
<soapenv:Header>
</soapenv:Header>
<soapenv:Body>
<out6:struct1 xmlns:out6="http://www.test.com/">
<struct2>
<yourtags>a</yourtags>
</struct2>
</out6:struct1>
</soapenv:Body>
</soapenv:Envelope>
You will get this output:
<?xml version="1.0" encoding="utf-8"?>
<RootElement xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope">
<out6:struct1 xmlns:out6="http://www.test.com/">
<struct2>
<yourtags>a</yourtags>
</struct2>
</out6:struct1>
<message_err/>
</RootElement>
If you have this XML:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope">
<soapenv:Header>
</soapenv:Header>
<soapenv:Fault>exception bla bla
</soapenv:Fault>
</soapenv:Envelope>
You will get this output:
<?xml version="1.0" encoding="utf-8"?>
<RootElement xmlns:soapenv="http://www.w3.org/2001/12/soap-envelope"> <message_err>exception bla bla
</message_err>
</RootElement>
*Note, if you want to remove all the namespaces you can add a second XSL in your operation mapping:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="comment() | text() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
Hope this helps.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.