Re: Templates, Q Names and namespaces

Subject: Re: Templates, Q Names and namespaces
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Thu, 23 Nov 2000 04:23:12 -0800 (PST)
Hi Paul,

No reasons to worry -- your stylesheet will work without modifications,
as long as the namespace-uri for the different prefixes continues to be
the same (in your case ""). 

You'll continue to access my:elem by specifying m:elem, whatever:elem
-- as long as the "m:" and "whatever:" prefixes have been used in a
namespace declaration that associates them to the same namespace-uri --
in your case "". The reverse is also true -- you can
change the prefixes or use several different prefixes in your source --
as long as they've been associated with the same namespace-uri as the
prefix used in your stylesheet, then your stylesheet will continue to
access by the same Q-name the nodes with the changed prefixes.

You can check this for yourself with a simple stylesheet.
This is the correct behaviour of an XSLT processor according to the
XSLT/XPath specifications. I've verified that SAXON and MSXML 3 perform
exactly in this way.

In case the default namespace is re-defined in your source xml
document, then it will not be possible from a stylesheet to access by
name any un-preffixed elements (in scope of the redefinition) in the
source document -- even in the case when the same default namespace
redefinition is specified in the stylesheet.

Dimitre Novatchev.
-------------------------Original message ----------

In an XML document, I might have an element

<my:elem xmlns:my="">...</my:elem>

In a stylesheet, I can write something like:

<xsl:apply-templates select="my:elem"/>

<xsl:template match="my:elem">...</xsl:apply-templates>

Now, if I apply my stylesheet a new document containing:

<m:elem xmlns:m="">...</m:elem>

my stylesheet will no longer work. Equally, I could be using a default
namespace in the source document.

What is the simplest way to make my stylesheet independent of the
used for the namespace, while keeping it correctly attached to the
URI itself? And are there known XSL implementations where this doesn't
(I know implementations of namespaces in some XSL implementations is



 XSL-List info and archive:

Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.

 XSL-List info and archive:

Current Thread