cancel
Showing results for 
Search instead for 
Did you mean: 

XML to string using xslt or java mapping

former_member182412
Active Contributor
0 Kudos

Hi Experts,

I want to put xml into string and i need to change lessthan symbol to "&lt" and greaterthan symbol to "&gt" , can anyone please help me how to do this??? can you provide code for java mapping or XSLT mapping to achive this.

SOURCE

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

<ns0:source_mt xmlns:ns0="urn:ppp:prototype">

<row>

<name1>IT</name1>

<name2>SOLUTIONS</name2>

</row>

</ns0:source_mt>

TARGET

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

<ns0:target_mt xmlns:ns0="urn:ppp:prototype">

<row>

<Body>"&lt"name1"&gt" IT"&lt"/name1"&gt" "&lt"name2"&gt" SOLUTIONS"&lt";/name2"&gt" </Body>

</row>

</ns0:target_mt>

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi ,

here is the XSLT code to obtain the desired output


<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<ns0:target_mt xmlns:ns0="urn:ppp:prototype">
	<xsl:for-each select="//row">
		<row>
			<Body>
				<xsl:for-each select="name1">
						<xsl:value-of select="concat('*&quot;&lt;&quot;name1&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name1&quot;&gt;&quot;*')"></xsl:value-of>
				</xsl:for-each>	
				<xsl:for-each select="name2">
						<xsl:value-of select="concat('*&quot;&lt;&quot;name2&quot;&gt;&quot;*',normalize-space(.),'*&quot;&lt;&quot;/name2&quot;&gt;&quot;*')"></xsl:value-of>
				</xsl:for-each>
			</Body>
		</row>
	</xsl:for-each>
</ns0:target_mt> 	
</xsl:template>

</xsl:stylesheet>

output produced as viewed in browser is

http://postimage.org/image/1lqbgw8kk/

Now to obtain exactly the output you posted earlier here is the code


<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<ns0:target_mt xmlns:ns0="urn:ppp:prototype">
	<xsl:for-each select="//row">
		<row>
			<Body>
				<xsl:for-each select="name1">
						<xsl:value-of select="concat('*&quot;&amp;lt&quot;name1&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name1&quot;&amp;gt&quot;*')"></xsl:value-of>
				</xsl:for-each>	
				<xsl:for-each select="name2">
						<xsl:value-of select="concat('*&quot;&amp;lt&quot;name2&quot;&amp;gt&quot;*',normalize-space(.),'*&quot;&amp;lt&quot;/name2&quot;&amp;gt&quot;*')"></xsl:value-of>
				</xsl:for-each>
			</Body>
		</row>
	</xsl:for-each>
</ns0:target_mt> 	
</xsl:template>

</xsl:stylesheet>

output you can see from link below

http://postimage.org/image/2c7bzo478

Hope this helps.

Hi,

Could you please kindly let us know if the solution is working properly as per your requirement?

regards

Anupam

Edited by: anupamsap on Jul 26, 2011 6:29 AM

Edited by: anupamsap on Jul 26, 2011 4:10 PM

Answers (2)

Answers (2)

Shabarish_Nair
Active Contributor
0 Kudos

use - http://wiki.sdn.sap.com/wiki/display/XI/WholePayloadtoaXML+field

in the java code, just put a replaceAll java method to chance the < to lt and > to gt.

ex;

payload = payload.replaceAll("<", "&lt;");
payload = payload.replaceAll(">", "&gt;");

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Have you seen this link?

/people/jyothi.anagani/blog/2010/06/17/convert-the-input-xml-to-string-in-pi-71-using-standard-graphical-mapping

Use Return as XML option in the mapping to achieve this. I believe you use PI 7.1 and above.

If your version is below 7.1 then use

http://wiki.sdn.sap.com/wiki/display/XI/JavaMapping-ConverttheInputxmlto+String