cancel
Showing results for 
Search instead for 
Did you mean: 

xmlanonymizer bean and xslt - both not working for namespace change

Former Member
0 Kudos

Hi All

I have a source structure below

<ns1:Product_MT xmlns:ns1="urn:alpha:websub" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Header>

----

---

</Header>

<Item>

--


---

</Item>

</ns1:Product_MT>

I am using a soap sender getting called from SOAP UI to consume a PI web service and  send the output message to receiver HTTP channel

the receiver needs the namespace of the XML structure as below (ns1 changed to ns)

<ns:Product_MT xmlns:ns="urn:alpha:websub" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<Header>

----

---

</Header>

<Item>

--


---

</Item>

</ns:Product_MT>


I tried to put the xmlanonymizer bean in receiver HTTP but its not doing anything. I am stil getting the output with ns1 namespace

Attached screenshot of receiver http adapter configuration in module


also, I tried to use XSLT mapping as below but this is also not doing anything. Probably, the XSL has to be modified to use in my case . Please help. and let me know.

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

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">

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

<xsl:template match="/">

<ns:Product_MT xmlns:ns="urn:alpha:websub">

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

</ns:Product_MT>

</xsl:template>

</xsl:stylesheet>

thx

mike

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try the following -

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:ns="urn:alpha:websub" version="1.0">

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

  <xsl:variable name="root">Product_MT</xsl:variable>

  <xsl:template match="*">

    <xsl:choose>

      <xsl:when test="local-name()=$root">

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

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

        </xsl:element>

      </xsl:when>

      <xsl:otherwise>

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

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

        </xsl:element>

      </xsl:otherwise>

    </xsl:choose>

  </xsl:template>

</xsl:stylesheet>

Regards,

Sameej

Former Member
0 Kudos

Thanks Sameej. This works in XMLSPY but not in PI Operation mapping

I am getting the error as

  • javax.xml.transform.TransformerException: java.lang.RuntimeException: Namespace for prefix 'ns' has not been declared.
    at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:771)

My source structure has ns1 namespace and it should work according to XMLSPY test but not working in PI ..any help? anyone?

mike

Former Member
0 Kudos

I had to tweak the XSL little bit to make it work in PI. See updated version below -

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

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

   <xsl:variable name="root">MT_Product</xsl:variable>

   <xsl:variable name="rootns">urn:mdt:udiwebsubmission</xsl:variable>

   <xsl:template match="*">

     <xsl:choose>

       <xsl:when test="local-name()=$root">

         <xsl:element name="ns:{local-name()}" namespace="{$rootns}">

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

         </xsl:element>

       </xsl:when>

       <xsl:otherwise>

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

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

         </xsl:element>

       </xsl:otherwise>

     </xsl:choose>

   </xsl:template>

</xsl:stylesheet>

Regards,

Sameej

Former Member
0 Kudos

thx a ton Sameej. you resolved the issue. I'm doing a operation mapping wherein I have to place this XSL as the 2nd mapping and first would be message mapping. The other way is not working because it just removes the ns namespace from the final target message after the message mapping.

thx again

mike

Answers (1)

Answers (1)

former_member184720
Active Contributor
0 Kudos

What is the value you have given for accept namespace?

it should be urn:alpha:websub ns

Former Member
0 Kudos

yes, Hareesh. thats exactly I gave there

Former Member
0 Kudos

I have a message mapping and can I use the xslt or udf to achieve this because the anonymizer bean is not helping for my case due to some unknown reason

mike