[xsl] overriding namespaces

Subject: [xsl] overriding namespaces
From: "michael shea" <michaellshea@xxxxxxxxxxx>
Date: Fri, 30 May 2003 08:14:05 +1000
Hi All,

We currently have a problem whereby we need to change the namespace declared 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 the input document, which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.test.com/v4.0/test";>

As you can see the namespace is http://www.test.com/v4.0/test. This will work correctly when the namespaces match, but we also have the case whereby the input document could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.test.com/v5.0/test";>

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 because the namespaces differ. So my question is, does anyone know of a way to have different namespaces handled by the same stylesheet?

I know one solution would be to double up the code inside the stylesheet to 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 the 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 generate your stylesheet with another stylesheet with the correct version in the header?" , well due to the intricacies of the way our stylesheets are used, we can't do this).

Thanks in advance for any help.

ninemsn Extra Storage is now available. No account expiration - no need to worry about losing your Hotmail account. Go to http://join.msn.com/?page=dept/home&pgmarket=en-au

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

Current Thread