RE: [xsl] ***********Transformation of an XML document containing a default namespace ************

Subject: RE: [xsl] ***********Transformation of an XML document containing a default namespace ************
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Thu, 25 Oct 2001 10:52:47 +0100
> >According to the spec, you _never_ get any control over th eprefixes
> >used, and it is perfectly OK for an XSLT serialiser to always use
> >prefixes like kmsqzzxss1: kmsqzzxss2: .... even if the
> stylesheet uses
> >fo: or whatever.  (So this is the no, it can't be done answer)
> >
> >However most (all?) systems do in fact try to preserve the namespace
> >prefixes in most situtaions.
>
> Can we not, however, assume that the processor has to preserve the
> namespace prefix regardless of what the Spec says?

Actually, the spec does require that namespace prefixes are preserved, to
some degree. Specifically, there are certain operations (such as xsl:copy,
or processing a literal result element) that cause namespace nodes to be
added to the result tree. A namespace node contains both the namespace
prefix and the URI. When serializing, every namespace node must result in a
namespace declaration that associates that prefix with that URI.

There are other operations such as <xsl:element> and <xsl:attribute> that
write a node to the result tree without creating a namespace node. In this
situation, the only requirement is that the output must assign some prefix
to the relevant namespace URI.

When the serializer outputs an element or attribute name, it can use any
prefix it likes that's assigned to the right namespace URI. In practice this
fact is only interesting in cases where the result tree has either (a) no
in-scope namespace nodes for that namespace URI or (b) several in-scope
namespace nodes for the same namespace URI. Where there is exactly one, it
will in practice choose that prefix.

The model is changed in the XSLT 1.1 WD so that the process of "namespace
fixup" happens while building the result tree rather than while serializing
it, but the effect is the same, except that the rules are tightened to
prevent the processor from inventing unnecessary namespace declarations out
of thin air: in effect, if there is exactly one namespace node for the
namespace URI, the processor is now obliged to choose that one.

Mike Kay


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


Current Thread