Topic
1 reply Latest Post - ‏2012-11-01T08:34:17Z by HermannSW
Michael_V
Michael_V
8 Posts
ACCEPTED ANSWER

Pinned topic XPATH into Extracted CDATA

‏2012-10-31T19:15:12Z |
I have a SOAP request with CDATA contained in the body. Once I extract out the CDATA I then need to XPATH (either by using a XSLT or a conditional action) into it to determine the service/routing-url. My problem is that DataPower doesn't seem to be recognizing that the contains of CDATA is an XML document once I extract it. Any ideas how I can fix this?

And why doesn't the probe should be the contains of my cdata variable?

Thanks, Michael

------------------------DOCUMENTATION------------------------

SOAP BODY

<AL3><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<?ACORD version = "1.3.0"?>
<ACORD>
<InsuranceSvcRq>
<CommlAutoPolicyQuoteInqRq>
</CommlAutoPolicyQuoteInqRq>
</InsuranceSvcRq>
</ACORD>
]]></AL3>

EXTRACT XSL

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="/AL3">
<xsl:variable name="v_CdataContent" select="."/>
<xsl:value-of select="$v_CdataContent" disable-output-escaping="yes"/>
</xsl:template>

</xsl:stylesheet>

EXTRACTED CDATA

<?xml version="1.0" encoding="UTF-8"?>
<?ACORD version = "1.3.0"?>
<ACORD>
<InsuranceSvcRq>
<CommlAutoPolicyQuoteInqRq>
</CommlAutoPolicyQuoteInqRq>
</InsuranceSvcRq>
</ACORD>

ROUTING XSL
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:dpconfig="http://www.datapower.com/param/config" xmlns:dpfunc="http://www.datapower.com/extensions/functions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" extension-element-prefixes="dp dpfunc dpconfig" exclude-result-prefixes="dp dpconfig dpfunc xsd xsi">
<xsl:template match="/">
<xsl:choose>
<xsl:when test="/ACORD">
<dp:set-variable name="'var://service/routing-url'" value="'http://mydomain.com/myservice/service1'"/>
</xsl:when>
<xsl:when test="/"> <!---ALWAYS GETS HERE--->
<dp:set-variable name="'var://service/routing-url'" value="'http://mydomain.com/myservice/service2'"/>
</xsl:when>
<xsl:otherwise>
<xsl:message dp:priority="error">
<xsl:value-of select="'Could not determine Routing URL'"/>
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Updated on 2012-11-01T08:34:17Z at 2012-11-01T08:34:17Z by HermannSW
  • HermannSW
    HermannSW
    4138 Posts
    ACCEPTED ANSWER

    Re: XPATH into Extracted CDATA

    ‏2012-11-01T08:34:17Z  in response to Michael_V
    Hi,

    after parsing your input the CDATA section does not exist anymore.
    Anyway, the content of your AL3 element is a text node, as can be seen here:
    $ xpath++ "string(/AL3)" acord.xml 
    &​lt;?xml version="1.0" encoding="UTF-8"?>
    &​lt;?ACORD version = "1.3.0"?>
    &​lt;ACORD>
    &​lt;InsuranceSvcRq>
    &​lt;CommlAutoPolicyQuoteInqRq>
    &​lt;/CommlAutoPolicyQuoteInqRq>
    &​lt;/InsuranceSvcRq>
    &​lt;/ACORD>
     
    $
    


    You can do what you want -- after parsing the string as XML by dp:parse():
    $ xpath++ "dp:parse(/AL3)/*/*/*" acord.xml 
    <CommlAutoPolicyQuoteInqRq>
    </CommlAutoPolicyQuoteInqRq>
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:46:33Z at 2014-03-25T02:46:33Z by iron-man