Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Default namespace

Status
Not open for further replies.

JJR

Programmer
Apr 11, 2001
180
NL
Hi,

I´m using an xsl stylesheet to create xsl:fo, which run through a parser outputs pdf. Now the problem I am having is with the namespaces in the xml file.

Beside of the xsi namespace we added a default namespace just in case of future use of this xml by third parties.

Without the default namespace in the xml my xsl workes fine. With the default namespace included in the xml however, without taking any action, my xsl can´t find any of the nodes I'm referring to.

And this I think is odd. The reason of a default namespace is to assign all the nodes without any prefix to this namespace. so it should be logical (to me..), to call them in the xsl by just using their name because they don't have any prefix. But ... this doesn't work.

The only way around this I found, is to include the same namespace in the xsl and add a prefix (lets say a:). Then I must refer to my nodes in the xml (who don't have a prefix) by applying the prefix to them.

Puzzeled yet??

So lets say I have a node in my xml called

Code:
<Banking>

In my xsl I match the node like this:
Code:
<xsl:template match=&quot;Banking&quot;>

With the proper codes around it this workes!! Now I include the following namespace in my xml:

Code:
<Banking xmlns=&quot;some.uri.nl&quot;>

The node &quot;Banking&quot; doesn't have a prefix, so it is assigned to the default namespace. Now if I apply the same xsl it will not find the node!!

But when I modify the xsl:stylesheet node in my xsl like this:

Code:
<xsl:stylesheet version=&quot;1.0&quot; xmlns:a=&quot;some.uri.nl&quot;
 xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL]
 xmlns:fo=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Format&quot;>[/URL]

and modify the matching pattern like this:

Code:
<xsl:template match=&quot;a:Banking&quot;>

The code works again!!

Now I like to know if there is a way around this?? I want to use a default namespace in my xml, but preferably I don't want to go through my entire stylesheet to add a prefix to every single node because of this.

I hope someone (you??) can answer this long question,

Jordi Reineman
Cap Gemini Ernst & Young
 
i think that when you add the default namespace it breaks the namespace inside the xsl document.

so with your <banking xmlns=&quot;bank&quot;>, all those xml nodes are in the input file's default namespace but not the stylesheet's default namespace. the default namespace of the stylesheet is the &quot;null&quot; namespace.

so maybe you need
<xsl:stylesheet version=&quot;1.0&quot; xmlns=&quot;some.uri.nl&quot;
 xmlns:xsl=&quot; xmlns:fo=&quot;
to put the stylesheet in the same namespace.

this is from my understanding of the theory and not from any practice, so i don't claim this to be THE answer :)
 
Hi MrTom,

Thanks for your swift reply. Yes that would be logical and yes I've tried this, but as I wrote, this will not work unless you add the prefix (with all the consequences).

Thanx for your thinking anyway..

Jordi Reineman
 
Hi everyone,

I found the answer! You are obliged to add a prefix. It's in the requirements.

Found the answer to exactly my problem here:


I'll write a faq, because there will be more of you who will run into this problem.

Greetings,

Jordi Reineman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top