RE: [xsl] overriding namespaces

Subject: RE: [xsl] overriding namespaces
From: "Dion Houston" <dionh@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 May 2003 19:33:33 -0700
Hi Mike:

You have found what some (like me) consider to be a feature of XPath,
that is namespace awareness.  Basically elements in a different domain
are considered distinct, regardless of how similar they may be in domain

In your particular situation, I would advise against attempting to have
one generic stylesheet that handled both versions.  My preferred
solution would be to archive your existing stylesheets, and recreate
them with the new namespace.

Among the reasons:

- Archiving your existing stylesheets would guarantee results if you
needed to do a v4.0 only run in the future.  Should you wish to change
your stylesheets for 5.0 while maintaining the behavior for 4.0, you can
easily change them if they're separate.

- Should you wish to do new behavior with your stylesheets in some
cases, but not in others, having two stylesheets would allow you to
import the old one, and fall back whenever you desire.

- This would lead to the simplest, cleanest implementation of templates
on two separate sets of objects.

Should you really desire to have one stylesheet, then you have a few
options (in order of ugliness):

1. Make each of your template matches match on both element names (i.e.
match="v4:foo | v5:foo")

2. Match on the local name (match="*[local-name()='root']")

3. Massage out the namespaces and apply on the null names (i.e.

<xsl:variable name="massaged">
   <xsl:apply-templates mode="removeNamespaces"/>
<xsl:variable name="massaged.ns" select="vendor:node-set($massaged)"/>

<xsl:template match="*" mode="removeNamespaces">
   <xsl:element name="local-name()">

<xsl:apply-templates select="$massaged.ns"/>
<xsl:template match="root">


Dion Houston

-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of michael shea
Sent: Thursday, May 29, 2003 3:14 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] overriding namespaces

Hi All,

We currently have a problem whereby we need to change the namespace
for a certain entity depending on the namespace that will be in the XML 
input.  As an example, here is the a sample of the stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/">
      <xsl:value-of select="/test:root/test:name"/>

In this example, we are trying to output the /root/name text value of
input document, which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="";>

As you can see the namespace is  This
work correctly when the namespaces match, but we also have the case
the input document could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="";>

Notice the only difference is the v5.0 instead of v4.0 in the namespace.

Now running the stylesheet again, there is no output for the name
the namespaces differ. So my question is, does anyone know of a way to
different namespaces handled by the same stylesheet?

I know one solution would be to double up the code inside the stylesheet
include a check for both versions, but this is not an ideal solution.

One method I tried was to import a dummy stylesheet with a namespace of 
xmlns:test that the user could change to suit whatever version they were

currently working on, but this didn't work.

Another method suggested was to pass in the version as a parameter to
stylesheet, however I don't know how to get this to work especially 
considering the namespace declarations are declared in the header of the

stylesheet (which might lead to the next response, "why don't you
your stylesheet with another stylesheet with the correct version in the 
header?" , well due to the intricacies of the way our stylesheets are
we can't do this).

Thanks in advance for any help.

ninemsn Extra Storage is now available. No account expiration - no need
worry about losing your Hotmail account. Go to

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread