xml - XSLT Transformation create a soap fault -


i need create xslt transforms response message soap fault. tried creating xslt result not expected.attached input,expected output,xslt , result after xslt transformation. can please help.

input:

 <response>                     <metadata>                     </metadata>                     <message-body>                         <errors>                             <transaction-id>12345</transaction-id>                             <claim-id>124545454</claim-id>                             <suffix-id>545454</suffix-id>                             <messages>                                 <message-id>123</message-id>                                 <message-type>e</message-type>                                 <message-description>claim not found</message-description>                             </messages>                             <messages>                                 <message-id>256</message-id>                                 <message-type>m</message-type>                                 <message-description>username not valid</message-description>                             </messages>                         </errors>                     </message-body>   </response> 

expected output:

            <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">                         <soap:header />                         <soap:body>                             <soap:fault>                                 <soap:code>                                     <soap:value>soap:sender</soap:value>                                 </soap:code>                                 <soap:detail>                                         <soap:text  xml:lang="en">[e]100000:userid not found;[m]100001:source system not found</soap:text>                                 </soap:detail>                             </soap:fault>                         </soap:body>                     </soap:envelope> 

xslt:

        <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">          <xsl:output  method="text"/>          <xsl:strip-space elements="*"/>           <xsl:template match="/">                   <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">                     <soap:header />                     <soap:body>                         <soap:fault>                             <soap:code>                                 <soap:value>soap:sender</soap:value>                             </soap:code>                             <soap:detail>                                     <soap:text  xml:lang="en"><xsl:apply-templates/></soap:text>                             </soap:detail>                         </soap:fault>                     </soap:body>                 </soap:envelope>           </xsl:template>            <xsl:template match="messages[position() > 1]">             <xsl:text>,</xsl:text>             <xsl:apply-templates/>           </xsl:template>            <xsl:template match="messages/*">             <xsl:value-of select="substring(';', 1, position() > 1)"/>             <xsl:value-of select="substring('[', 1, name()='message-id')"/>             <xsl:value-of select="."/>             <xsl:value-of select="substring(']', 1, name()='message-id')"/>           </xsl:template>         </xsl:stylesheet> 

result:

<soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">        <soap:header/>        <soap:body>           <soap:fault>              <soap:code>                 <soap:value>soap:sender</soap:value>              </soap:code>              <soap:detail>                 <soap:text xml:lang="en">12345124545454545454[123];e;claim not found,[256];m;username not valid</soap:text>              </soap:detail>           </soap:fault>        </soap:body>     </soap:envelope> 

help appreciated

i. wrong matching:

following piece of code wrong:

<soap:detail>     <soap:text  xml:lang="en"><xsl:apply-templates/></soap:text> </soap:detail> 

your context-node "/", document node. process entire input-xml (as long there isn't matching template, not process further childs). background knowledge, xslt got default copy-text-to-output technique, wrong content element.

suggested change:

<soap:detail>   <soap:text  xml:lang="en"><xsl:apply-templates select="/response/message-body/errors/messages"/></soap:text> </soap:detail> 

ii. wrong output-method:

<xsl:output  method="text"/> 

will output text-strings. change method xml.


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -