Subject: Re: [xsl] problem w/ namespaces From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 30 Apr 2002 16:48:41 +0100 |
Hi Jakub, > I am trying to define namespace of my xml data and I do it like > > <?xml version="1.0"?> > <xsl:stylesheet version="1.0" xmlns:xsl > ="http://www.w3.org/1999/XSL/Transform"> > <xsl:template match="/"> > <CbaMessage xmlns="http://www.deio.net/cbamessage" ... > > In the output of the transformation the root elemnt (CbaMessage) has > correct namespace, but all direct children elements of <CbaMessage> > look like this > > <Transport xmlns=""> > > I want the namespace to be valid for all elements not just for the > root. How can I do it? When you create an element in XSLT, then you have to tell the processor what namespace you want that element to be in, but you can leave the fiddly stuff about putting namespace declarations on elements up to the processor. In your case, you're telling the processor that the CbaMessage element is in the namespace 'http://www.deio.net/cbamessage' and you're telling it that the Transport elements are in no namespace. To make that work in the output, it has to add xmlns="" attributes -- making the default namespace no namespace -- to the Transport elements in the result. You want the Transport elements, the CbaMessage elements, indeed all the elements that you're generating, to be in your namespace. The namespace of a literal result element is determined just like normal elements in XSLT -- by the namespace declarations on its ancestors *within the stylesheet*. So the easiest way to get what you're after is to move the default namespace declaration from the CbaMessage literal result element (where it will only affect the contents of that CbaMessage element *in the stylesheet*) to the xsl:stylesheet element. This will give the namespace declaration scope throughout the stylesheet; any elements that don't have a prefix will be in your namespace. The processor then only has to put a namespace declaration on the document element. So do: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.deio.net/cbamessage"> <xsl:template match="/"> <CbaMessage ... Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] problem w/ namespaces, Jakub . Valenta | Thread | RE: [xsl] problem w/ namespaces, Michael Kay |
[xsl] loading XML message with JAVA, Derous Benny | Date | Re: [xsl] problem w/ namespaces, David N Bertoni/Camb |
Month |