|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: xsl:element and namespace output
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








