Subject: RE: [xsl] Node renaming problem|
From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Date: Thu, 10 Oct 2002 10:08:33 -0600
> I want to add a prefix to a particular node tree such that > <math> > <apply> > <power/> > <ci>x</ci> > <cn>2</cn> > </apply> > </math> > > becomes > > <m:math> > <m:apply> > <m:power/> > <m:ci>x</m:ci> > <m:cn>2</m:cn> > </m:apply> > </m:math>
Presumably you want the result to be well-formed XML, in which case the "m" namespace must be declared? If not (and perhaps anyway), your best bet is to do a global replace using a text editor.
Giving the elements a prefix of "m" is cosmetic.
The key question is what namespace you want the elements in. You haven't bound "m" to any namespace. The spec says "the QName is expanded into an expanded-name (ie., a namespace-uri/local-name pair) using the namespace declarations in effect for the xsl:element element". It doesn't actually say what happens if the prefix isn't in scope. Interestingly, this omission is still present in the XSLT 2.0 draft. My interpretation has always been that it is an error, but your XSLT processor seems to interpret it differently, or to attempt a recovery action. > > This is the result using MSXSL4.0: > <m:math xmlns=""> > <m:apply xmlns=""> > <m:power xmlns="" /> > <ci>x</ci> > <cn>2</cn> > </m:apply> > </m:math>
This isn't well-formed XML, so I don't think any XSLT processor should produce this result. Raise a bug report.
> 3) Am I overcomplicating everything? > The key question is, are you trying to produce namespace-well-formed XML output, and if so, what namespace do you want it in?
Greg Faron Integre Technical Publishing Co.