Topic
  • 3 replies
  • Latest Post - ‏2013-11-04T19:22:17Z by JoeMorganNTST
mbscott
mbscott
2 Posts

Pinned topic Issue with access soap element store in DP conext variable

‏2013-10-31T15:38:31Z |

Hi Guys,  I am trying to access soap element value <KeyId>0003481737</KeyId> and want to store 0003481737 in context variable var://context/txn/keyvalue.
below are input soap and xslt. and i am getting

below is output in conext variable. how to strip of namespaces and element tag.

Content of Variable 'var://context/txn/keyvalue':

    <KeyId
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://service.externalobm.com/"
    >0003481737</KeyId>

    
Input

<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns1:getResponse
        xmlns:ns1="http://service.externalobm.com/">
            <return>
                <ExceptionCode>NO_DATA_FOUND</ExceptionCode>
                <mainBranch>false</mainBranch>
                <KeyId>0003481737</KeyId>
            </return>
        </ns1:getResponse>
    </soap:Body>
</soap:Envelope>

xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"
 xmlns:dp="http://www.datapower.com/extensions"
  xmlns:func="http://exslt.org/functions"
  xmlns:dpfunc="http://www.datapower.com/extensions/functions"
  xmlns:dpconfig="http://www.datapower.com/param/config"
  xmlns:dyn="http://exslt.org/dynamic"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://service.externalobm.com/"
  extension-element-prefixes="dp func dpfunc dpconfig dyn"
  exclude-result-prefixes="dp func dpfunc dpconfig dyn">  

<xsl:template match="soap:Envelope">

<xsl:choose>
    <xsl:when test="soap:Body/ns1:getResponse/return/ExceptionCode">
         <!-- Found the node(s) -->
<dp:set-variable name="'var://context/txn/Exception'" value="'1'"/>
<dp:set-variable name="'var://context/txn/keyvalue'" value="soap:Body/ns1:getResponse/return/KeyId"/>
    </xsl:when>
    <!-- more xsl:when here, if needed -->
    <xsl:otherwise>
         <!-- No node exists -->
<dp:set-variable name="'var://context/txn/Exception'" value="'2'"/>
    </xsl:otherwise>
</xsl:choose>
<!-- Populating output from context variable -->                    
<xsl:variable name="InputMsg" select="dp:variable('var://context/txn/InputData')"/>
    <xsl:copy-of select="$InputMsg"/>  
</xsl:template>  
</xsl:stylesheet>

 

  • swlinn
    swlinn
    1348 Posts

    Re: Issue with access soap element store in DP conext variable

    ‏2013-10-31T20:02:16Z  

    How about

    <dp:set-variable name="'var://context/txn/keyvalue'" value="string(soap:Body/ns1:getResponse/return/KeyId/text())"/>

    you can drop the string function if you don't care if it is not visible in the probe as it should work in a consuming xslt regardless, but i always like to verify in the probe.

    Regards,

    Steve

  • mbscott
    mbscott
    2 Posts

    Re: Issue with access soap element store in DP conext variable

    ‏2013-11-04T16:43:43Z  
    • swlinn
    • ‏2013-10-31T20:02:16Z

    How about

    <dp:set-variable name="'var://context/txn/keyvalue'" value="string(soap:Body/ns1:getResponse/return/KeyId/text())"/>

    you can drop the string function if you don't care if it is not visible in the probe as it should work in a consuming xslt regardless, but i always like to verify in the probe.

    Regards,

    Steve

    Thanks swlinn, it works.

  • JoeMorganNTST
    JoeMorganNTST
    427 Posts

    Re: Issue with access soap element store in DP conext variable

    ‏2013-11-04T19:22:17Z  
    • mbscott
    • ‏2013-11-04T16:43:43Z

    Thanks swlinn, it works.

    For what it's worth, I have a reusable XLST for that kind of thing (Attached).  Can't say it's documented all that well, but when you select it, it will ask for an XPATH expression and a variable name.  Enter the variable name without the "var://" part.

    So, once you select the attached XSLT, you'd see two new fields show up.  You'd then enter the XPATH expression exactly as Steve has it, then in the variable field, you'd enter "context/txn/keyvalue".

    You can use the XPATH tool too, to help with future needs.

    Hope this helps.

     

    Attachments

    Updated on 2013-11-04T19:23:15Z at 2013-11-04T19:23:15Z by JoeMorganNTST