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

Re: Can one element have more than one namespaces?

Subject: Re: Can one element have more than one namespaces?
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 27 Mar 2001 10:33:21 +0100
xmlns y
Hi Dave,

> So the answer is no? I can't differentiate between the two elements
> in my example, since the only difference is the 'extra namespace in
> scope',

Your example was:

> given two different elements,
> element A in ns X and Y
> element A in ns X
>
> How do I do a template match to select the first one?

Chris explained that there can be no such thing as 'element A *in* ns
X and Y' as an element can only ever be *in* one namespace.

Perhaps you meant:

element A with ns declarations for X and Y
element A with ns declaration for X

In other words, something like:

<B>
  <A xmlns:x="X" xmlns:y="Y" />
  <A xmlns:x="X" />
</B>

or:

<B xmlns:x="X">
   <A xmlns:y="Y" />
   <A />
</B>

(Note that the A and B elements are all in the *null* namespace in
this example - they don't have prefixes, and there's no default
namespace declaration.)

> Can't the namespace axis be used for this purpose?

Yes, the namespace axis can be used to differentiate between nodes
that have different namespaces *in scope*. You can match the A element
that has namespace declarations for both X and Y with the template:

<xsl:template match="A[namespace::x and namespace::y]">
   ...
</xsl:template>

Note that the 'x' and 'y' (the namespace prefixes) come from the
*source* XML document, not from the declarations in the XSLT
stylesheet.  So the above template would work even if the stylesheet
declared the X and Y namespaces with completely different prefixes, or
didn't declare them at all.

However, if you changed the prefixes in the source to a and b instead:

<B xmlns:a="X">
   <A xmlns:b="Y" />
   <A />
</B>

Then the match pattern wouldn't match either A element because neither
has namespaces with the prefixes 'x' or 'y'.

Cheers,

Jeni

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



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.