This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Can one element have more than one namespaces?


Hi Dave,

> Your example
>
> <B>
>   <A xmlns:x="X" xmlns:y="Y" />
>   <A xmlns:x="X" />
> </B>
>
> this has ns declarations 'for' two ns. 
> Which ns is the first A element 'in'?
> Or is that a factor of the prefix used? I.e. they are in the null ns?

Absolutely.  The namespace that an element or attribute is *in* is a
factor of their name.  The name is made up of a prefix and a local
name.  The prefix indicates the namespace that the element or
attribute is in.

Thus, all the elements in the above are have no prefixes, so they are
in the *default* namespace. In the example, the default namespace
hasn't been declared, so they are in the *null* namespace.

> So the subtleties appear to be differentiating between
> the (single) ns an element is *in*
> the (possibly multiple) ns declared *for* the element
> the (possibly multiple) ns's *in scope* 
> (Guess that the latter two are equivalent?)

Yes, the latter two are equivalent.  Technically, a namespace
declaration adds a namespace node to the element the namespace
declaration is on, and to all the elements it has as descendants.
That namespace is 'in scope' to that element and all its descendants.

> Which leaves the 'null' ns and no ns declaration.
> Equivalent?
> <A xmlns:x="" />
> and <A>

Not precisely equivalent.

<A xmlns:x="" />

Translates to:

+- (element node) A - null namespace
   \- (namespace node) xml
   \- (namespace node) x

Whereas:

<A />

Translates to:

+- (element node) A - null namespace
   \- (namespace node) xml

Both A elements are in the same (null) namespace, but the first has a
namespace node named 'x' on it.  The example you're missing is:

<x:A xmlns:x="" />

which is almost exactly the same as:

<A xmlns:x="" />

The only difference from XSLT's point of view is that the name()
function will return 'x:A' for the former and 'A' for the latter.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]