Re: [xsl] Why does using the XSL namespace default namespace preclude literal result elements in the empty namespace?

Subject: Re: [xsl] Why does using the XSL namespace default namespace preclude literal result elements in the empty namespace?
From: tcn@xxxxxxxxxxxxx (Trevor Nash)
Date: Sat, 21 Jul 2001 15:32:25 GMT
On Sat, 21 Jul 2001 09:35:40 -0400 (Eastern Daylight Time), Mark
Nahabedian <naha@xxxxxxxxxx> wrote:

>Aaron Hope writes:
> > I know that's a long subjetct but the instructions said to be specific...
> > 
> > I've got a stylesheet with 80-90% of elements in the xsl namespace, the 
> > rest being literal result elements destined for html output.  All those 
> > xsl: prefixes add up to a lotta noise, and well, i can't help but feel 
> > there should be a way to avoid it.  If what i gather from the 1.0 spec 
> > is correct, then these elements can't simply be in an html: namespace 
> > (html 4.0 or xhtml, say).  I know I can replace them with <element> and 
> > <attribute> tags, but, again, that's a lot of noise and you end up 
> > putting in c-like terminator comments, e.g. </element><!-- table -->. 
> >  At first I read the namespace-alias entry and I said "Ooh, there we 
> > go!", but no, since you can't have empty namespaces other than the 
> > default, there's no way to set the result namespace to the null namespace.  
>The XSLT and HTML names are in different namespaces.  Those namespaces 
>can not both be the default namespace at the same time.  What I do is
>pick the one that it's the biggest nuissance to type the prefix for
>(usially XSLT) as the default namespace.
> > So, after all that here's my question: why can't i say
> > <namespace-alias stylesheet-prefix="html" result-prefix="#none"/>?  (or 
> > #empty or #null, etc)
Because namespace-alias is used to swap one namespace for another.  It
has nothing to do with what prefix the XSLT processor uses in the
output: you do not get any control over this, though most processors
try to follow what is in the input.
It is a feature of the namespace recommendation that the empty
namespace cannot be associated with a prefix.  I.e. you can say
xmlns="" but not xmlns:null="".  If you want the empty namespace in
the output, then you have to reserve the default namespace for literal
result elements.  I guess somebody somewhere knows why?

>What's wrong with using the zero length string, as in
>    <namespace-alias stylesheet-prefix="html" result-prefix=""/>
This is not legal.  The default namespace is referred to by '#default'
not ''.  Besides, the effect would be to declare the output elements
in the XSLT namespace, which is not what you want.

>Admittedly, the one time I recall trying to do this it didn't work,
>but I attributed that to a bug in the processor I was using, which was
>beta software.

One way to address this problem, and other perceived shortcomings of
XSLT syntax, is to write a stylesheet which takes something like

<template match="/">

and produces

 xmlns:xsl=""; version="1.0"
<xsl:template match="/">

Its not hard.  Though you will have to understand what namespace-alias
really does, and you may end up finding out more than you really want
to know about white space handling ;-)

Trevor Nash
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

 XSL-List info and archive:

Current Thread