cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT mapping to replcae ns1 from output xml payload

Former Member
0 Kudos


Hi,

My main graphical mapping is returning payload as below and same is been passed to third party but we need to replace "ns1" string from output payload to 'pidx".

Could you please provide me the XSLT code to achive the same or is there any better approach to do it.

Graphical output payload:

Required Output:

Thanks & Regards,

Nid Fatima

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

If you just want to change the prefix, you can go for XMLAnonymizerBean

refer to below wiki.

Changing Namespaces and the encoding format of XML - Process Integration - SCN Wiki

If you really want xslt then

Refer to Udo's reply for sample code :

Former Member
0 Kudos

Hi Hareesh,

Your Option1 worked for me.

Thank you.

Regards,

Nida

Answers (3)

Answers (3)

nabendu_sen
Active Contributor
0 Kudos

Hi Nida,

You can just simply open the Message Mapping and Edit the <XML Namespace> section with any desired value you want. It is easy and don't need any customization. Check the below blog and give it a try:

Original MT:

Modified MT:

Reference:

Regards,

Nabendu.

Harish
Active Contributor
0 Kudos

Hi Nida,

you can also achive this with graphical mapping by using below code in Attribute and method UDF

public void transform(TransformationInput in, TransformationOutput out)

  throws StreamTransformationException {

try {

  String sourcexml = ""; String targetxml =""; String line ="";

  InputStream ins =    in.getInputPayload().getInputStream();

  BufferedReader br = new BufferedReader( new InputStreamReader(ins));

  while ((line = br.readLine()) != null) 

  sourcexml +=line;//+"\n"; 

  br.close();

  targetxml =sourcexml;

  targetxml = targetxml.replaceAll("ns1", "pidx");

  out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

  } catch (Exception e) {   throw new StreamTransformationException(e.getMessage());   }

}

  public String concate(String str1, String str2, Container container) throws StreamTransformationException{

  //String output = null;

  return (str1+str2);

  }

iaki_vila
Active Contributor
0 Kudos

Hi Nida,

As you haven't written a complete example, i have done one, may be something is lost but you can do a generic XSL for this purpose.

From this XML:


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

<ns1:ROOT xmlns:ns1="http://example.org"  ns1:test="" ns1:version="1.0">

<ns1:MORETAGS>a</ns1:MORETAGS>

</ns1:ROOT>

If you use this XSL:


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

<xsl:stylesheet version="1.0"

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

   xmlns:ns1="http://example.org"

   xmlns:pidx="http://example.org"

   exclude-result-prefixes="ns1">

   <xsl:output method="xml" encoding="UTF-8" indent="yes"/>

   <xsl:template match="/">

         <xsl:copy>

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

         </xsl:copy>

   </xsl:template>

   <xsl:template match="ns1:*">

      <xsl:element name="pidx:{local-name()}">

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

      </xsl:element>

   </xsl:template>

   <xsl:template match="@ns1:*">

      <xsl:attribute name="pidx:{local-name()}">

         <xsl:value-of select="."/>

      </xsl:attribute>

   </xsl:template>

</xsl:stylesheet>

You will get this output:


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

<pidx:ROOT xmlns:pidx="http://example.org" pidx:test="" pidx:version="1.0">

<pidx:MORETAGS>a</pidx:MORETAGS>

</pidx:ROOT>

Regards.