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,

> 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


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