cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping in SAP CPI to replace special characters & return output in XML format only

krishma_bhatia16
Explorer
0 Kudos

Hello,

I am new to XSLT mapping in SAP CPI and need your help. I have XML input in the format shown below and want output also to be in same XML format only.The only condition is to replace special characters(HTML encoded) like & to & in Value tag.I tried the below XSLT mapping, but it is not working, and the output is no longer in XML format. Can anyone please help?

Input XML:-

input-xml.jpg

XSLT Mapping code:-

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:epcis="urn:epcglobal:epcis:xsd:1" xmlns:sbdh="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:sap="http://sap.com/xi/STTP/SAPExt" xmlns:cbvmda="urn:epcglobal:cbv:mda" xmlns:gs1ushc="http://epcis.gs1us.org/hc/ns" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:custom="http://localhost:8080/customFunctions" xmlns:tl="http://epcis.tracelink.com/ns" exclude-result-prefixes="custom gs1ushc xs xsi">
	<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="no"/>
	<xsl:strip-space elements="*"/>
	
	    <xsl:template match="/">
            <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
        </xsl:template>

        <!--<xsl:template match="/entry/properties/Id[contains(text(),'ENDPOINT')]">-->
        <xsl:template match="/entry">
            <xsl:for-each select="/properties">
                <xsl:value-of select="Value" disable-output-escaping="yes"/>
            </xsl:for-each>
        </xsl:template>
        
</xsl:stylesheet>
<br>

Output:-

sap-cpi-output.jpg

Thanks in advance!

Regards,

Krishma

ziolkowskib
Active Contributor
0 Kudos

Hi krishma_bhatia16,
If you replace & with & you will make your XML invalid from the syntax perspective. In such case whatever is in <d:Value> should be put in CDATA.

<d:Value><![CDATA[http://www.sap.com?param=SAP&value=System]]></d:Value>

Regards,
Bartosz

Accepted Solutions (0)

Answers (1)

Answers (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Krishma,

Below might help you.

Input XML:

<root>
	<record>
		<Field1>123</Field1>
		<Field2>ew3</Field2>
		<Field3>https://www.sap.com/∫erface=sisisi</Field3>
	</record>
	<record>
		<Field1>122</Field1>
		<Field2>ew1</Field2>
		<Field3>https://www.sap.com/∫erface=sisisi1</Field3>
	</record>
</root><br>

XSLT:

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

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

    <xsl:template match="/root/record">
        <xsl:value-of select="." disable-output-escaping="yes"/>
    </xsl:template>
</xsl:transform><br>

Output XML:

<root>
	  <record>
		    <Field1>123</Field1>
		    <Field2>ew3</Field2>
		    <Field3>https://www.sap.com/∫erface=sisisi</Field3>
	  </record>
	  <record>
		    <Field1>122</Field1>
		    <Field2>ew1</Field2>
		    <Field3>https://www.sap.com/∫erface=sisisi1</Field3>
	  </record>
</root><strong><br></strong>

Also whenever you post question please try to add XML message instead of screenshot that would help to provde aswers quickly.

Regards,

Sriprasad Shivaram Bhat