cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT Mapping: Namespace for prefix 'ns0' has not been declared

Former Member
0 Kudos

Hello, I am working on a synchronous SOAP call and having some trouble with the response message. The web service has its own namespace and I am trying to convert this to my custom data type in PI. PI wants the message to be in format of having ns0 prefix and namespace like we have defined (http://foo for example).

I have an XSLT mapping (see below) which works fine with my test response payload (pulled from SXMB_MONI source) on this online XSLT test site:

http://www.freeformatter.com/xsl-transformer.html

However when I import this archive to PI and test with operation mapping it always says "Namespace for prefix 'ns0' has not been declared."

This is very confusing because when I test it online, I see both prefix and namespace declaration perfectly. Is there a way to see the results in the PI test tool? After this XSLT java error it doesn't give me the output even in Trace Level All mode.

Please advise on this issue or if you know an easier way (such as altering my datatype/message type to match the inbound SOAP message). I tried working with the 3rd party WSDL but the response message types show a different root level node than what PI is receiving so I gave up to make my own matching datatype. I just have to solve this last inbound namespace issue and should be finished.

FYI I have refreshed all PI caches and activated all objects.

Thanks for your ideas!

<xsl:stylesheet version="1.0"

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

xmlns:ns0="http://foo"

  <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>

  <xsl:template match="@* | node()">

    <xsl:copy>

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

    </xsl:copy>

  </xsl:template>

  <xsl:template match="/*">

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

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

    </xsl:element>

  </xsl:template>

  <xsl:template match="/">

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

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

    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Aaron,

Your xslt worked for me after two small changes:  (1) I assigned the namespace directly when creating the ns0 element. (2) Changed the last template match to "*".   Please see below:


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

  <xsl:template match="node()|@*">

    <xsl:copy>

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

    </xsl:copy>

  </xsl:template>

  <xsl:template match="/*">

    <xsl:element name="ns0:{local-name()}" namespace="http://foo">

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

    </xsl:element>

  </xsl:template>

  <xsl:template match="*">

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

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

    </xsl:element>

  </xsl:template>

</xsl:stylesheet>

Thanks,

-Russ

Former Member
0 Kudos

Perfect, thanks Russ. I can confirm this worked great. I also noticed your node patterns were reversed from mine, not knowing much about XSL syntax not sure if these are equivalent (but I used yours).

In the mean time I also found a work around to just extract the XSD and re-import it as an External Definition using the namespaces I wanted. It is good to know about both methods.

Thanks again,

Aaron

Answers (1)

Answers (1)

Former Member
0 Kudos

Some additional info, here is an example payload which goes through the XSLT mapping perfectly, but in PI I get the error about missing ns0 declaration.

XML input:

<bar xmlns='http://irrelevantnamespace'

xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'

xmlns:xsd='http://www.w3.org/2001/XMLSchema'

xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>

<foo/>

</bar>

XSLT mapped output using test tool and XSL above:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:bar xmlns:ns0="http://foo">
  
<foo />
</ns0:bar>

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Try like this  to declare namespace prefix nso in your first line

<bar xmlns:nso='http://irrelevantnamespace'

or you can see xmlanonymizerbean to remove prefix (if you don't want the namespace prefix)

Former Member
0 Kudos

Thanks Baskar, but the source message is coming from 3rd party so I can't change it part. Thats why I'm trying XSLT mapping.

Source message also has no root prefix but PI always requires 'ns0' for some reason as part of our free-hand data types.

So I must add the prefix and namespace for the SOAP response message, but I think the xmlanonymizerbean only lets us take away namespaces.