on 11-18-2014 9:08 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.