Subject: Re: [xsl] xsl:element and namespace output From: David N Bertoni/Cambridge/IBM <david_n_bertoni@xxxxxxxxxx> Date: Wed, 26 Feb 2003 09:03:22 -0800 |
> I am relatively new at this but I have been reading the list and I've > tried to do my own leg work. But I need some help now. I want to > transform xml to another xml moving data to diff. tag names and > adding a namespace declaration to the root. I've read, searched and > done a lot of trial and error and here's where I am: > > <xsl:element name="RRRRR" namespace="http://www.aaa.com/bbb/ccc"> > <xsl:element name="TTT111"> > <xsl:value-of select="concat(some source xml tags)"/> > </xsl:element> > > <xsl:element name="TTT222"> > <xsl:value-of select="concat(some source xml tags)"/> > </xsl:element> > > <xsl:element name="TTT333"> > <xsl:attribute name="AAA333">12345678</xsl:attribute> > > <xsl:element name="TTT444"> > <xsl:element name="TTT555">somedata</xsl:element> > <xsl:element name="TTT666"> > <xsl:value-of select="a source xml tag"/> > </xsl:element> > > I want a simple default namespace declaration on the root in the > output xml. The xsl:element for RRRR does that. But on all children > at the first level below RRRR it's generating xmlns="". So TTT222, > TTT333 get this xmlns="" in the output. I don't understand why > except it's clearing the namespace so they don't belong to the RRRR > namesspace. But the entire output xml should belong to the same > namespace. Seems like it's doing the opposite of what I intended and > thought it would do. > > Could someone explain and enlighten me? If you want all of the elements in that namespace, you must create them that way: <xsl:element name="TTT222" namespace="http://www.aaa.com/bbb/ccc"> <xsl:value-of select="concat(some source xml tags)"/> </xsl:element> etc. You're thinking the processor is generating serialized XML, so one default namespace definition is all you need, but that's not the case. The processor is creating a tree of nodes, the result tree, and serializing that. If it detects there's a default namespace in scope, and it serializes an element node whose tag name has no prefix, and the element node has a null namespace URI, it must "turn off" the default namespace. You might want to experiment with some variations of xsl:element to understand how this all works. Try creating some element in various namespace and use both prefixed and unprefixed names and see what happens. Dave XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] xsl:element and namespace out, ETarlton | Thread | [xsl] XSL performance with key from, Bhandari, Ashish |
RE: [xsl] Re: The Perils of Sudden , Américo Albuquerque | Date | [xsl] XSL-FO versus PostScript, Zack Brown |
Month |