Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2300

Re: XSLT to remove namespace prefix

$
0
0

Hi Nida,

 

you can create a one to one message mapping and the below code in "Attributes and Methods" section. This will remove the ns1 namespace.

 

If you have more namespace prefix then you need to add all the namespace prefix

 

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:", "");

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

 

 

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

}

 

reference - Write Java Mapping directly in ESR!

 

Also if you really want to go for XSLT then use the below XSL code

 

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" version="1.0" encoding="UTF-8" />

        <xsl:template match="*">

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

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

                </xsl:element>

        </xsl:template>

</xsl:stylesheet>

 

but the best way is to achieve this using XMLAnonymizer module because it is standard feature.

 

Remove Namespace in PI by XMLAnonymizer Bean in... | SCN

 

regards,

Harish


Viewing all articles
Browse latest Browse all 2300

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>