cancel
Showing results for 
Search instead for 
Did you mean: 

XSLT-Mapping Exception: Prefix not mapped:

Former Member
0 Kudos

Hi all,

I try to make a mapping using XSLT and get the exception: Prefix not mapped: ns0.

I wrote a simple xslt-script:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://me.home.com">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="//XIFCollection">
 <Start>
  <xsl:for-each select="ns1:XIFTest">
   <Found>
    <xsl:number format="1"/>
   </Found>
  </xsl:for-each>
 </Start>
</xsl:template>
</xsl:stylesheet>

Using this input XML:


<?xml version="1.0" encoding="UTF-8"?>
<XIFCollection  >
 <ns0:XIFTest xmlns:ns0="http://me.home.com">
  <IFControl>
   <MeldungsId>1</MeldungsId>
  </IFControl>
  <XTest>
  </XTest>
 </ns0:XIFTest>
 <ns0:XIFTest xmlns:ns0="http://me.home.com">
  <IFControl>
   <MeldungsId>2</MeldungsId>
  </IFControl>
  <XTest>
  </XTest>
 </ns0:XIFTest>
</XIFCollection>

In XML-Spy I get the following output:


<?xml version="1.0" encoding="UTF-8"?>
<Start xmlns:ns1="http://me.home.com">
 <Found>1</Found>
 <Found>2</Found>
</Start>

What I expected.

But using XI or the XML-Toolkit XI30xslt I get the exception:

java.lang.Exception: XMLParser: Prefix 'ns0' is not mapped to a namespace.

I tried everything and searched all dokumentation but have no idea.

Anyone with an idea?

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

udo_martens
Active Contributor
0 Kudos

Hi Denise,

i didnt test it, but i'm optimistic you can solve your problem if you additional declare that prefix in the stylesheet element:

xmlns:ns0="http://me.home.com"

Regards,

Udo

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

you need to chage as Udo said

but also the other ns0 one:

check this:

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

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

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

<xsl:template match="//XIFCollection">

<Start>

<xsl:for-each select="ns0:XIFTest">

<Found>

<xsl:number format="1"/>

</Found>

</xsl:for-each>

</Start>

</xsl:template>

</xsl:stylesheet>

BTW

it works in Stylus Studio now

Regards,

michal

Former Member
0 Kudos

Thanks for the fast replies.

I had the same ideas and tried them before. But that doesn’t help.

The only way of getting this to run is deleting the namespaces or set only the root element of the XML-Input to a namespace.

But I can't see why it is not working like I described. I think this is XML-conform?

Thanks so far

henrique_pinto
Active Contributor
0 Kudos

There's a namespace conceptual error here.

If you want your xml tags, all of them, to belong to a certain namespace, you have two ways of doing it.

1. you can reference that namespace prefix before every tag, separated by ':';

2. you can just use the xmlns attribute in the root tag, and all the child tags inserted in that root tag will also belong to that namespace; but in this case, you don't need to use the prefix.

So, just remove the 'ns0' prefix of the XIFTest tags in your input xml. Or put ns0 prefix in all of it's child tags.

Regards,

Henrique.