Project

Profile

Help

how to remove namespace

Added by Anonymous almost 18 years ago

Legacy ID: #3882908 Legacy Poster: Arek R. (ryar)

I've to insert a text to my xml file somewhere in the middle like <xxx> <yyy></yyyy> </xxx> After transformation I got <xxx xmlns=""> <yyyy></yyyy< </xxx> What should I do set to not generate this: xmlns="" ?


Replies (5)

Please register to reply

RE: how to remove namespace - Added by Anonymous almost 18 years ago

Legacy ID: #3883071 Legacy Poster: Michael Kay (mhkay)

Please read this recent thread from xsl-list: http://www.biglist.com/lists/xsl-list/archives/200608/msg00573.html Saxon outputs xmlns="" because you have created an element that's not in a namespace, as a child of an element that is in a namespace. If you don't want the xmlns="", this probably means that you want the element to be in the same namespace as its parent, and the way to achieve that is to put it there when you create it. Change the instruction that created the element (a literal result element, an xsl:element instruction, or perhaps xsl:copy or xsl:copy-of so that it sets the namespace part of the element name correctly. Michael Kay http://www.saxonica.com/

RE: how to remove namespace - Added by Anonymous almost 18 years ago

Legacy ID: #3949857 Legacy Poster: Anton Brazhnyk (darkace)

It would be quite usefull to be able to work with 'top level' namespace by default. And it would be logicaly consistant with xml-spec. I mean it seems ok (at least for me) to expect that when I'm adding child using Document.createElement() to parent with namespace it inherits NS. If I want to change NS I use createElementNS(). It probably violates some specs, but it's the way a lot of popular transformers/parsers go. So, probably it worth of adding some parameter to saxon, which will allow this questionable but very convinient spec violation? :)

RE: how to remove namespace - Added by Anonymous almost 18 years ago

Legacy ID: #3949882 Legacy Poster: Michael Kay (mhkay)

The semantics of XSLT are that the name of an element is decided at the time the element is created, and can't be changed when the element is added to a new parent. It would be a very disruptive change to the semantics to change this. In principle one could create an element whose name has a namespace component of "undecided", so that the namespace is actually determined subsequently when the element is attached to a parent - but namespace handling is complicated enough without adding such extra refinements.

RE: how to remove namespace - Added by Anonymous almost 18 years ago

Legacy ID: #3949902 Legacy Poster: Anton Brazhnyk (darkace)

I'm shocked by such a quick answer. :) Let's try to go to specific problem (or example) if you don't mind. :) I'm actually talking about empty transformation in Java, when I just want to output xml to some stream. I use Transformer without any xsl and in case of xalan (which is default in most of JREs) it generates elements without xmlns attribute, effectively defaulting namespace. When I use saxon I'm getting xmlns="". I completely agree it's legal and conforming to the specs, but I wouldn't like to write complex code to track namespace during xml construction. Especialy when document contains more then one NS. So, is there any chance we can get some kind of "compatibility / lazy coders" mode in saxon? :)

RE: how to remove namespace - Added by Anonymous almost 18 years ago

Legacy ID: #3949938 Legacy Poster: Michael Kay (mhkay)

If there's an incompatibility between Saxon and Xalan then it would be a good idea to raise it on the xsl-list at mulberrytech.com so that we can have a discussion about which is right. You need to provide actual code, cut down to the minimum to demonstrate the problem. Under no circumstances will I introduce a non-conformance into Saxon in order to reproduce bugs that are present in competitive products.

    (1-5/5)

    Please register to reply