[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xmlns=""

Subject: Re: xmlns=""
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 22 Feb 2011 14:19:29 +0000
Re:  xmlns=""
On 22 February 2011 14:08, Merrilees, David
<David.Merrilees@xxxxxxxxxxxx> wrote:
> Hi
> When I add a default namespace to an element, it's direct descendants
acquire an xmlns="". Does anyone know why this is, or how to avoid it?
> Input:
> <?xml version="1.0" encoding="UTF-8"?>
> <html>
>        <head>
>                <title>Vmtejte</title>
>        </head>
>        <body id="home">
>        <body>
> </html>
> XSL:
> <xsl:template match="/html">
>        <html xmlns="http://www.w3.org/1999/xhtml">
>                <xsl:sequence select="./node()"/>
>        </html>
> </xsl:template>
> Output:
> <?xml version="1.0" encoding="UTF-8"?>
> <html xmlns="http://www.w3.org/1999/xhtml">
>        <head xmlns="">
>                <title>Vmtejte</title>
>        </head>

In your input xml the element is:


so both elements are in no namespace.

In your transform you have:

  <html xmlns="http://www.w3.org/1999/xhtml">

which is an element in the xhtml namespace, and all unprefixed
elements beneath that in the result tree will also be in the xhtml

When you copy the unprefixed head element (that is in no namespace) to
the result tree, then you have 2 unprefixed elements, one in the xhtml
namespace and one in no namespace:

<html xmlns="http://www.w3.org/1999/xhtml">
  <head xmlns="">

So the head element must have the xmlns="" to indicate its in no
namespace, rather than the xhtml namespace.

The solution is create new a head element in the xhtml namespace - you
cant copy it from the source as its name cant change.  To create the
new head, either write literally <head> in your transform or use the
element constructor.

To make things easier until the joys of default namespaces become
clearer, either use a prefix for the xhtml namespace in your transform

<x:html xmlns:x="http://www.w3.org/1999/xhtml">

or put your input into a namespace:

<html xmlns="whatever">

...and then its a bit easier to see whats going on.

Andrew Welch

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.