[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Getting rid of xmlns="" attributes ( doubt )


Subject: RE: [xsl] Getting rid of xmlns="" attributes ( doubt )
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 2 Jan 2004 18:08:27 -0000

Let's use the notation {uri}local to refer to the expanded name of an
element.

If you write the literal result element <template xmlns=""> in your
stylesheet, then the element name (in both the stylesheet and the result
document) is {}template - i.e. local name "template", in no namespace.

In the result tree, a processor can always ensure that the template
element is in "no namespace" by writing <template xmlns="">. However,
most processors will avoid redundant namespace declarations, and the
xmlns="" is redundant if there is no outer element with a namespace
declaration such as xmlns="something".

As I said before, don't worry about namespace declarations. Only worry
about (expanded) element names. Put the element in the right namespace,
and leave the serializer to worry about getting the namespace
declarations right.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of deva
> Sent: 02 January 2004 19:50
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Getting rid of xmlns="" attributes ( doubt )
> 
> 
> Hi guys,
> Just a quick question,
> 
> for the xml ..
> 
> <?xml version="1.0" encoding="utf-8"?>
> <template>
>   <exportTimeStamp xmlns="">
>     <date>2003-12-29</date>
>     <time>15:31:34</time>
>   </exportTimeStamp>
>   <templateInfo xmlns="" name="" id="1139410602" revision="1">
>     ...
>   </templateInfo>
>   ...
> </template>
> 
> i just made a small modification to the XSL Allen had 
> done,....Just added xmlns = "" to the template element, and I 
> could see no extra xmlns attributes.. I think It works that 
> way.I am trying to reason now. By forcing the template 
> element with an empty namespace, I am asking the processor to 
> produce the template element and all its children in an empty 
> namespace. and so it doesnt show up. am i right?
> 
> My XSL
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
> xmlns="http://tempuri.org/FormSchema.xsd"
> 
> xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
> version = '1.0'>
> 
> <xsl:output method="xml"/>
> 
> <xsl:template match="/template">
> <template xmlns = "">
> <xsl:attribute name="version">
> <xsl:value-of select="@version"/>
> </xsl:attribute>
> <xsl:attribute name="readVersion">
> <xsl:value-of select="@readVersion"/>
> </xsl:attribute>
> <xsl:copy-of select="*"/>
> </template>
> </xsl:template>
> 
> </xsl:stylesheet>
> Thanks
> 
> ==============================================================
> ==============
> ==
> Allen Wrote:
> I've been using XSL for a few months now and I've been given 
> a request for a transformation of our XML document into 
> another XML document, with only some slight changes. One of 
> the changes is to remove a xml:space="preserve" attribute, 
> but I consider that a trivial problem that I can easily 
> solve. (I'm just explicitly writing the element with the two 
> other attributes that appear.) The bigger problem is that I 
> need to add two namespaces to the XML. From what I've read on 
> this list, the best place to do something like that is to 
> place the namespace definitions within the <xsl:stylesheet> 
> element. I've done that, but now all the child elements have 
> xmlns="" appearing within them. My XSL looks like this:
> 
> <?xml version="1.0" encoding="iso-8859-1"?>
> <xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
> xmlns="http://tempuri.org/FormSchema.xsd"
> 
> xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance"
> version = '1.0'>
> 
> <xsl:output method="xml"/>
> 
> <xsl:template match="/template">
> <template>
> <xsl:attribute name="version">
> <xsl:value-of select="@version"/>
> </xsl:attribute>
> <xsl:attribute name="readVersion">
> <xsl:value-of select="@readVersion"/>
> </xsl:attribute>
> <xsl:copy-of select="*"/>
> </template>
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> The transformation appears to work fine, except, as I said, 
> the child elements of the root <template> element, all have 
> the attribute xmlns="". A short snippet of it would be this:
> 
> 
> 
> I've found that if I change the namespace in the 
> <xsl:stylesheet> from xmlns to xmlns:y, then I don't get the 
> rogue attribute, but that is also giving me the incorrect 
> namespace. The source XML does not have any namespaces 
> defined within it, and I think that I read somewhere that the 
> <xsl:copy-of> might have issues with that. Is there anyway to 
> get the namespaces to come out correctly, without giving me 
> the xmlns=""?
> 
> Erik Allen
> 
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords