cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT to transform string within CDATA to a XML structure

Former Member
0 Kudos

Hi,

I have an  interface where the message has all the required fields within the CDATA segment. 

Below is the request:

<ns1:return ns1:type="com.skire.webservices.util.xml.XMLObject">

            <ax21:statusCode xmlns:ax21="http://xml.util.webservices.skire.com/xsd">200</ax21:statusCode>

          <ax21:xmlcontents xmlns:ax21="http://xml.util.webservices.skire.com/xsd"><![CDATA[<?xml version="1.0" encoding="ISO-8859-1"?>

<List_Wrapper>

          <_user>

                    <employee>UPDATE2</employee>

  <uuu_user_loginname>XYZ</uuu_user_loginname>

                    <uuu_user_homephone>123</uuu_user_homephone>

                    <uuu_user_workphone>987</uuu_user_workphone>

  <uuu_user_proxy></uuu_user_proxy>

          </_user>

</List_Wrapper>]]>

</ax21:xmlcontents>

         </ns1:return>

Desired Output :

<ax21:statusCode xmlns:ax21="http://xml.util.webservices.skire.com/xsd">200</ax21:statusCode>

<_user>

  <employee>UPDATE2</employee>

  <uuu_user_loginname>XYZ</uuu_user_loginname>

  <uuu_user_homephone>123</uuu_user_homephone>

  <uuu_user_workphone>987</uuu_user_workphone>

  <uuu_user_proxy></uuu_user_proxy>

  </_user>

I have done a XSLT:

<xslt:stylesheet

xmlns:xslt="http://www.w3.org/1999/XSL/Transform"

version="1.0">

<xslt:output omit-xml-declaration="yes"/>

<xslt:template match="result">

<xslt:value-of disable-output-escaping="yes" select="."/>

</xslt:template>

</xslt:stylesheet>

But i am missing something. It does not work.


Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thank you !! it was really helpfull Amit Srivastava


Former Member
0 Kudos

Hello,

This can be achieved  in two steps: 1) graphical and then 2) XSLT

In graphical mapping (first mapping under OM) using replace string function remove xml declaration (<?xml version="1.0" encoding="ISO-8859-1"?>) + <List_Wrapper> + </List_Wrapper> and then pass entire input as it is to XSLT

Then use below XSLT code (second mapping under OM):

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ax21="http://xml.util.webservices.skire.com/xsd">

   <xsl:output omit-xml-declaration="yes"/>

   <xsl:template match="@*|node()">

      <xsl:copy>

         <xsl:apply-templates select="@*|node()"/>

      </xsl:copy>

   </xsl:template>

  <xsl:template match="/">

<ax21:statuscode><xsl:value-of select ="//ax21:statusCode"/></ax21:statuscode>

  <xsl:value-of select= "//ax21:xmlcontents"  disable-output-escaping="yes"/>

</xsl:template>

</xsl:stylesheet>

Thanks

Amit Srivastava

Former Member
0 Kudos

Hi Amit/ Peter,

I would need the 200 as well. It is status of mt response.

Is there any way with which i can have the 200 alone with the flat structure after removing the Cdata string..

peter_wallner2
Active Contributor
0 Kudos

Hello Mithun,

In the java mapping you could check for your status code (e.g. 200) and integrate it into your XML structure. Which way do you want to go:

graphical mapping and XSLT

or

XSLT and java mapping?

Regards,

Peter

Former Member
0 Kudos

Hello,

The XSLT code which i have provided above will make sure that the status code field (

<ax21:statusCode xmlns:ax21="http://xml.util.webservices.skire.com/xsd">200</ax21:statusCode>

<_user>) also exist in the output structure.

Thanks

Amit Srivastava

peter_wallner2
Active Contributor
0 Kudos

Hello Mithun,

you could use this XSL:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:ax21="http://xml.util.webservices.skire.com/xsd"

    version="1.0">

    <xsl:template match="/">

        <xsl:apply-templates/>

    </xsl:template>

</xsl:stylesheet>

which gives you pretty much the same result as the one you have running already.

When I run yours or mine it gives me the output:

200 &lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
&lt;List_Wrapper&gt;
&lt;_user&gt;
&lt;employee&gt;UPDATE2&lt;/employee&gt;
&lt;uuu_user_loginname&gt;XYZ&lt;/uuu_user_loginname&gt;
&lt;uuu_user_homephone&gt;123&lt;/uuu_user_homephone&gt;
&lt;uuu_user_workphone&gt;987&lt;/uuu_user_workphone&gt;
&lt;uuu_user_proxy&gt;&lt;/uuu_user_proxy&gt;
&lt;/_user&gt;
&lt;/List_Wrapper&gt;

What I would do now is use a java mapping that reads in that string and replaces &lt; with "<" and &gt; with ">". The "200"

in the beginning you could also delete with the java mapping.

I hope that helps and best regards,

Peter