xsl-list
[Top] [All Lists]

RE: Generating XSLT

2004-11-15 20:16:26

If you don't preserve the prefix then when you use the target 
prefix in an 
attribute value (and the processor doesn't know which 
attribute values are 
qnames that require namespace prefix transliteration), then 
you end up with 
a disconnect.  Your emitted stylesheet includes namespace prefix uses 
without a resolved namespace URI.

This is indeed why XSLT 2.0 tightens up the rules for xsl:namespace-alias. 

The use case for this was the stylesheet:

<xsl:stylesheet version="2.0" 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:a="some.alias">

<xsl:namespace-alias stylesheet-prefix="a" result-prefix="xsl"/>

<xsl:template match="/">
  <v a:version="2.0" n="{{system-property('xsl:vendor')}}"/>
</xsl:template>

</xsl:stylesheet>

which (under the 2.0 rules) should generate the output stylesheet:

<v xsl:version="2.0" n="{system-property('xsl:version')}"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"/>

The XSLT 1.0 rules here are rather unclear. The specification says that the
result element will have a copy of the namespace nodes that were present on
the literal result element in the stylesheet, with the exception of any
namespace node whose namespace URI is the XSLT namespace. So the
xsl=http://..Transform namespace node is not copied, but the a=some.alias
namespace node is copied. It then says that a URI declared as an alias is
replaced by the URI that it is an alias for, giving you the namespace node
a=http://...Transform. Namespace nodes include both a prefix and a URI, and
there is nothing that says you are allowed to change the prefix. (The
processor can choose what prefix to use in element and attribute names, but
it can't change the name of a namespace node). So it appears that an XSLT
1.0 processor should generate:

<v a:version="2.0" n="{system-property('xsl:vendor')}"
   xmlns:a="http://www.w3.org/1999/XSL/Transform"/>

which won't actually work, because it uses (but does not declare) the prefix
"xsl".

In fact Saxon 6.5.3 generates:

<v xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:a="http://www.w3.org/1999/XSL/Transform"; 
   a:version="2.0" 
   n="{system-property('xsl:vendor')}"/>

which is a valid stylesheet, though a somewhat inelegant one. Adding an
extra namespace during serialization is something that the XSLT 1.0
specification permits, so this is conformant, however, there is nothing in
the xsl:namespace-alias specification that indicates that the extra
namespace is required.

Other vendors have found other ways of resolving this difficulty in the 1.0
spec.

Fortuitously, the XSLT 2.0 specification comes much closer to satisfying the
instinctive expectation that "result-prefix" will be the prefix used in the
result tree.

Michael Kay
http://www.saxonica.com/


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>