on 08-24-2016 6:21 PM
Hi,
I am working on Proxy to File(xml) scenario. In the output file we are getting namespace prefix for all the elements. Below is the screenshot of the same.
Our requirement is without prefix.
Can anyone help me with the XSLT code to manipulate the PI output.
PI output:
Required Output:
Thanks,
Nida Fatima
Hi Nida
If none of this works, you could try a different trick:
If you have designed the XSD in PI, you export it via copy paste to a xsd-file.
Then remove the namespace information in the .xsd-schema.
Then import this .xsd schema as an external definition back to PI and use this in the message type.
PI should then suppress the namespace information. It's a bit of a dirty trick, but I did it once successfully.
Regards
Jochen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fatima!
If you want to remove "ns1" prefix and use namespace of that prefix as value of attribute "xsi:schemaLocation" of your message's root node, you could use following XSL transformation:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0">
<xsl:output indent="yes"/>
<xsl:template match="/*">
<xsl:element name="{local-name()}">
<xsl:attribute name="xsi:schemaLocation"><xsl:value-of select="namespace-uri(.)"/></xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="comment() | text() | processing-instruction()">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
Regards, Evgeniy.
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 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()); }
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nida!
If you designed your source message/data types in ESR you can use "Qualify schema" parameter in Data Type editor.
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add Below Bean in receiver file channel to remove prefix:
AF_Modules/XMLAnonymizerBean
anonymizer.acceptNamespaces http://www.example.org/Order '' (2 single quotes)
anonymizer.quote '
Br,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.