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

utput 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

utput 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