RE: [xsl] Can one element have more than one namespaces?

Subject: RE: [xsl] Can one element have more than one namespaces?
From: "Christopher R. Maden" <crism@xxxxxxxxx>
Date: Mon, 26 Mar 2001 23:44:41 -0800
At 23:10 26-03-2001, DPawson@xxxxxxxxxxx wrote:
Which does raise the question,
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?

<xsl:template match="A[namespace::nsY and namespace:nsX]"> or something?

An element has one, and exactly one, name.


That name has a namespace URI and a local part.

The namespace part may be null, if there is no prefix and no default namespace in scope. This example has no namespace URI and a local part of "foo":

<foo xmlns=""/>

The namespace part may be a URI. In both of these examples, the URI is "http://crism.maden.org/consulting/example-namespace"; and the local part is "foo":

<foo xmlns="http://crism.maden.org/consulting/example-namespace"/>
<ex:foo xmlns:ex="http://crism.maden.org/consulting/example-namespace"/>

Now, this is getting confused with the namespace declarations in scope. An element only ever has one namespace. But more than one namespace *declaration* may be in scope for that element. In these examples, the element has the namespace http://crism.maden.org/consulting/example-namespace and a local part of "foo", but there are two namespace declarations in scope:

<ex:foo xmlns:ex="http://crism.maden.org/consulting/example-namespace";
  xmlns="http://crism.maden.org/consulting/example-namespace-2"/>
<foo xmlns="http://crism.maden.org/consulting/example-namespace";
  xmlns:ex="http://crism.maden.org/consulting/example-namespace-2"/>

These elements are of the same type.

In XPath 1.0, you must use a prefix to match an element type with a URI. In XSLT, the way to bind that prefix to a URI is to have namespace declarations in scope in the XML document that is the stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:ex="http://crism.maden.org/consulting/example-namespace";>

<xsl:template match="ex:foo"/>

</xsl:stylesheet>

That template matches *all* of the foo elements given above, except the first one (which has no namespace URI).

Clearer?

HTH,
Chris
--
Christopher R. Maden, XML Consultant
DTDs/schemas - conversion - ebooks - publishing - Web - B2B - training
<URL: http://crism.maden.org/consulting/ >
PGP Fingerprint: BBA6 4085 DED0 E176 D6D4  5DFC AC52 F825 AFEC 58DA


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



Current Thread