Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 24th, 2007, 12:28 AM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I suppress the unwanted xmlns in output

My xslt file transforms an XML file and output to new XML file.
It creates a new simple element as below:

<xsl:element name="newelement">xxx</xsl:element>

After a transformation, the output file created an additional null namespace attribute as below: :(

<newelement xmlns="">xxx</newelement>

How do I suppress the unwanted xmlns=" " from a transformed output xml file?

Please help!

 
Old November 24th, 2007, 04:52 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

When you create an element you must say what namespace it is to go in. The way you have invoked xsl:element asks for the element to go in the null namespace, so that is where it has gone. If you want it in a different namespace, use the namespace attribute to control this. It won't automatically go in the same namespace as its new parent element, which is presumably where you want it to go.

Namespace declarations are added by the serializer based on the names you have chosen for your elements (where the name is in two parts, namespace URI and local name). Your problem isn't an unwanted namespace declaration, your problem is that the element has been given the wrong name.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 24th, 2007, 05:15 PM
Registered User
 
Join Date: Nov 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

After review my xslt file, I discovered that I incorrectedly included a wrong namespace for the output's Root Node element (e.g. <MyRootNode xmlns="http://localhost:8081/XML"> )(*port 8081 never exists*).

By removing/or correcting my above xmlns namespace in my root element, the output results my generated elements without the "xslns=''" attribute.

Output:
    <newelement>xxx</newelement>
instead of
    <newelement xmlns="">xxx</newelement>

Problem solved. Thank you Michael for your good hint.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra xmlns="" tag in output Mango_Lier XSLT 4 October 16th, 2007 11:35 AM
XMLNS mathias XML 0 February 20th, 2007 04:46 AM
How to filter out unwanted data fdtoo SQL Server 2000 1 April 25th, 2006 10:44 AM
xmlns albusr .NET Web Services 0 December 24th, 2005 08:25 AM
Unwanted space... again Snib HTML Code Clinic 1 August 25th, 2004 04:45 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.