Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: default namespace and xmlns=""

From: mike@--------------------.--.-- (---- -------)
To: NULL
Date: 10/4/2004 9:25:00 AM
yes, that's what i meant, though possible put as have <z> inherit the
namespace of it's parent rather bind to "abc" specifically. this is
because there are potentially lots of z's...

"Marrow" <marrow@s...> wrote in message news:<8S98d.34$gN6.33@n...>...
> Hi Mike,
> 
> > my question is this. is it possible to remove the xmlns="" bit without
> > having to use <ns1:z> in the xslt?
> 
> It is not possible to 'remove' namespace declarations placed in the output
> by the transformation engine.  The transformation engine decides, to some
> degree under your instruction, what namespace declarations are needed.
> In this case your <z> element is bound to the null namespace (i.e. the
> namespace URI is "") - the only way to 'removing' that namespace declaration
> would be to bind the <z> element to a different namespace... which I
> suspect, but am not sure, is what you are asking... how to bind <z> to the
> "abc" namespace?
> 
> One way to start taking control of your output namespace is to define the
> default output namespace in your stylesheet, e.g.
> 
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:ns1="abc"
>  xmlns="abc">
> 
> The default namespace for the stylesheet is used as the default namespace
> for the output.
> 
> Having done that, then you only need to specify namespace prefixes (or
> @namespace-uri on <xsl:element>/<xsl:attribute>) where you want
> elements/attributes to be bound to a different namespace to the default
> output namespace.
> 
> Another thing that can help you 'control' (to a degree) the output namespace
> declarations is to use the <xsl:namespace-alias> instruction, for example to
> declare your prefix 'ns1' (e.g. xmlns:ns1="abc") in the stylesheet and then
> have that transposed to the default output namespace (e.g. xmlns="abc")
> would be to specify that...
> 
>  <xsl:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
> 
> So putting those together, your stylesheet might look like...
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:ns1="abc"
>  xmlns="abc">
> 
>  <xsl:namespace-alias stylesheet-prefix="ns1" result-prefix="#default"/>
> 
>  <xsl:output indent="yes" media-type="text/xml" standalone="yes"
> version="1.0"/>
>  <xsl:template match="/">
>   <x>
>    <ns1:y>
>     <xsl:apply-templates select="/a"/>
>    </ns1:y>
>   </x>
>  </xsl:template>
> 
>  <xsl:template match="/a">
>   <z>
>    <xsl:value-of select="b"/>
>   </z>
>  </xsl:template>
> </xsl:stylesheet>
> 
> which would give an output of...
> 
> <?xml version="1.0" encoding="UTF-16" standalone="yes"?>
> <x xmlns="abc">
>   <y>
>     <z>hello</z>
>   </y>
> </x>
> 
> Although then there would be no particular reason to declare the 'ns1'
> namespace prefix at all nor specify the @namespace-uri attribute on
> <xsl:element> (come to that, there is no particular reason to use
> <xsl:element> in this case at all).  So your stylesheet really just needs to
> be...
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns="abc">
> 
>  <xsl:output method="xml" indent="yes"/>
>  <xsl:template match="/">
>   <x>
>    <y>
>     <xsl:apply-templates select="/a"/>
>    </y>
>   </x>
>  </xsl:template>
> 
>  <xsl:template match="/a">
>   <z>
>    <xsl:value-of select="b"/>
>   </z>
>  </xsl:template>
> </xsl:stylesheet>
> 
> NB. Really, the only times when you need to use <xsl:element> is where the
> element name or namespace URI is being defined dynamically, i.e. where
> either the @name or @namespace-uri attributes contain an AVT (attribute
> value template).
> 
> HTH
> Marrow
> http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
> http://www.topxml.com/Xselerator
> 
> 
> 
> "Mike Dickens" <mike@p...> wrote in message
> news:721b66d8.0410040203.a7037ac@p......
> > hi,
> > i'm sure this has come up before but havn't managed to find an answer.
> > if i have the following xslt
> >
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> > <xsl:stylesheet method="xml" version="1.0" xmlns:ns1="abc"
> > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> >  <xsl:output indent="yes" media-type="text/xml" standalone="yes"
> > version="1.0"/>
> >  <xsl:template match="/">
> >   <x>
> >    <xsl:element name="y" namespace="abc">
> >     <xsl:apply-templates select="/a"/>
> >    </xsl:element>
> >   </x>
> >  </xsl:template>
> >  <xsl:template match="/a">
> >   <z>
> >    <xsl:value-of select="b"/>
> >   </z>
> >  </xsl:template>
> > </xsl:stylesheet>
> >
> > and apply it to the following xml
> >
> > <a>
> >  <b>hello</b>
> > </a>
> >
> > i get
> >
> > <?xml version="1.0" standalone="yes"?>
> > <x xmlns:ns1="abc">
> >   <y xmlns="abc">
> >     <z xmlns="">hello</z>
> >   </y>
> > </x>
> >
> > my question is this. is it possible to remove the xmlns="" bit without
> > having to use <ns1:z> in the xslt?
> >
> > thanks,
> > mike


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent