1

I am having issue using dp:serialize and Populate CDATA tag in response in datapower. Issue 1. Not able to convert to string from xml using dp:serialize function. Issue 2. Cdata tag not able to see in proble and soapui response page coming like <![CDATA[sometext]]>

Here is xslt that convert xml to string and populating in CDATA tag.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions"
  xmlns:dp="http://www.datapower.com/extensions">

    <xsl:output  method="xml" cdata-section-elements="ConfigurationXML"/>
    <xsl:variable name="Configxml" select="document('Config.xml')" />

    <xsl:template match="/">
     <xsl:variable name="Configstring">
     <dp:serialize select="$Configxml"/></xsl:variable>

     <Response>
       <ConfigurationXML>
                        <xsl:text disable-output-escaping="yes">&amp;lt;![CDATA[</xsl:text>
    <xsl:copy-of select="$Configstring"/> 
    <xsl:text disable-output-escaping="yes">]]&amp;gt;</xsl:text>       
                           </ConfigurationXML>         
      </Response>


    </xsl:template>
</xsl:stylesheet>
Mike
  • 35
  • 9

2 Answers2

1

You have to specify that the dp namespace prefix is an extension to the XSL language, otherwise the DataPower XSLT processor treats <dp:serialize> as normal XML data, and not an extension element.

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:dp="http://www.datapower.com/extensions"
    extension-element-prefixes="dp">
bjimba
  • 928
  • 8
  • 13
  • Thanks bjimba, I came to know this and implemented it is working fine. but after serialization also, it is coming as xml not string. do you know why? – Mike Jul 14 '16 at 12:16
  • Actual output after serialization: Node-set: DP http://test.com expected: string: DPhttp://test.com. I need string data type to compare with input. – Mike Jul 14 '16 at 12:50
  • How are you checking your output? Are you checking what's actually being returned, or are you looking at the DataPower probe? If you're using the probe, serialized data will *look* like it's XML, even when it's a string. – bjimba Jul 14 '16 at 17:19
  • Datapower probe is correct as u explained. I am looking at response in SOAP UI. basically my intension is need to compare xml that is coming in request cdata vs datapower configxml . both are same or not? – Mike Jul 15 '16 at 02:24
1

Instead of using copy-of when calling serialized data use value-of below code is work for you, here i called request dynamically not like from file.

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:dp="http://www.datapower.com/extensions">
<xsl:output method="xml" cdata-section-elements="ConfigurationXML"/>
<xsl:template match="/">
<xsl:variable name="Configstring1">
<xsl:copy-of select="."/>
</xsl:variable>
<xsl:variable name="Configstring2">
<dp:serialize select="$Configstring1"/>
</xsl:variable>
<Response>
<ConfigurationXML>
<xsl:text disable-output-escaping="yes">&amp;lt;![CDATA[</xsl:text>
<xsl:value-of select="$Configstring2"/>
<xsl:text disable-output-escaping="yes">]]&amp;gt;</xsl:text>
</ConfigurationXML>
</Response>
</xsl:template>
</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<Response xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:fn="http://www.w3.org/2005/xpath-functions" 
xmlns:dp="http://www.datapower.com/extensions">
 <ConfigurationXML>&lt;![CDATA[]]&gt;</ConfigurationXML>
</Response>