[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] Can exclude-result-prefixes alter the qualified name of an element?

Subject: [xsl] Can exclude-result-prefixes alter the qualified name of an element?
From: Carl Worth <cworth@xxxxxxxxxx>
Date: Fri, 28 Jan 2005 14:56:25 -0500

I've got an application in which the input tree (in namespace "input"
say) is allowed to contain sub-trees to appear directly in the output
tree (in namespace "output"). After the transformation, only nodes
from the output namespace will appear in the result.

As an example, I might have as input:

	<?xml version="1.0" ?>
	<i xmlns="input" xmlns:o="output">

and desired output:

	<?xml version="1.0" ?>
	<o xmlns="output">

The transformation I came up with is:

	<?xml version="1.0" ?>
	<xsl:stylesheet version="1.0"
	                exclude-result-prefixes="i o"
	  <xsl:template match="i:i">
	    <o:o xmlns="output">

	  <xsl:template match="o:e">
	    <xsl:copy-of select="."/>


An earlier version did not have the namespace declaration on the
literal <o:o> element, nor did it have the exclude-result-prefixes
attribute. That earlier version gave me a valid and correct result[*]:

	<?xml version="1.0"?>
	<o:o xmlns:o="output" xmlns:i="input">

But this is not as clean as what I set out for originally. It's got an
extraneous namespace declaration and unnecessary use of a prefix for
what could be the default namespace.

If I take the stylesheet as above, but using just a value of "o" for
exclude-result-prefixes, I get quite close to the desired result:

	<?xml version="1.0"?>
	<o xmlns="output" xmlns:i="input">

That's perfect except for one extraneous namespace declaration. And
the XSLT specification explicitly says that getting rid of something
like this is just what exclude-result-prefixes is designed for. But
when I use exclude-result-prefixes="i o", (in other words, using the
stylesheet exactly as quoted above), I get the following unexpected

	<?xml version="1.0"?>
	<o xmlns="output">
	  <e xmlns="input"/>

By simply excluding an unused namespace, the qualified name of the "e"
element has changed(!) from a namespace of "output" to "input", the
very namespace I was trying to exclude.

Is this a bug in this implementation, or can someone explain to me how
this behavior is justified by the specification?


[*] All example output cited here was produced with xsltproc:

	$ xsltproc --version
	Using libxml 20616, libxslt 10111 and libexslt 809
	xsltproc was compiled against libxml 20614, libxslt 10111 and libexslt 809
	libxslt 10111 was compiled against libxml 20614
	libexslt 809 was compiled against libxml 20614

[**] The following resources on namespaces were quite helpful:


Particularly the explanations of namespace nodes and the behavior of
copy-of with respect to namespace nodes.

Current Thread