Re: Generating namespace declarations given a result tree?

Subject: Re: Generating namespace declarations given a result tree?
From: James Clark <jjc@xxxxxxxxxx>
Date: Thu, 18 May 2000 12:18:58 +0700
John-Paul Sicotte wrote:

> To this xml
> 
> <element pos = "1"
>   xmlns:jpns1="http://www.messagingdirect.com/xml_namespaces/test1";
>   xmlns:jpns2="http://www.messagingdirect.com/xml_namespaces/test2";
>   xmlns:jpns3="http://www.messagingdirect.com/xml_namespaces/test3";
>   an_attribute = "jpns3:some_function()"
> />
>
> XT gives the following output (I have added whitespace)
> 
> <?xml version="1.0" encoding="utf-8"?>
> <element
>   pos="1"
>   an_attribute="jpns3:some_function()"
> 
>   xmlns:jpns1="http://www.messagingdirect.com/xml_namespaces/test1";
>   xmlns:jpns2="http://www.messagingdirect.com/xml_namespaces/test2";
>   xmlns:jpns3="http://www.messagingdirect.com/xml_namespaces/test3";
> />
> 
> Here none of the namespaces declared in the source tree are actually
> used in the xml so the output has redundant namespace declarations.
> However in this case the namespaces could be used by a meta parser to
> correclty interpret the attribute value.  This is the way xslt works
> with qnames in xpath expressions. XT in this case has also preserved the
> original namespace prefixes.
> 
> My question I guess boils down to this.  Is this just a feature that
> James Clark built into XT to get this extra functionality, or does the
> xslt spec gives some advice on this matter?

XSLT says you're supposed to output a tree T so that if you parsed it
back in again and constructed a tree using the XSLT data mdel you would
get a tree T' that was the same as T except that

- the order of attributes in T' and T may be different
- T' may have namespace nodes that are not in T

See 16.1. (There's a bit of additional complexity to do with document
fragments, but that's not relevant here.)

In this specific case, if you didn't output the namespace declarations
for jpns[1-3] then T would have namespace nodes that T' did not.  That's
not one of the differences that's allowed: XSLT only allows the
converse.  So you must output the namespace declarations for jpns[1-3].

If XSLT didn't do this, it would be difficult to use XSLT to transform
XSLT stylesheets.

Note that there are other kinds of redundancy that XSLT doesn't care
about.  For example:

<foo xmlns:x="abc"><bar xmlns:x="abc"/></foo>

and

<foo xmlns:x="abc"><bar/></foo>

are indistinguishable as far as XSLT are concerned.

James


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


Current Thread