RE: [xsl] Understanding xmlns declaration and encoding

Subject: RE: [xsl] Understanding xmlns declaration and encoding
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 8 Sep 2004 19:14:55 +0100
> When I exclude this
> xmlns="http://www.w3.org/1999/xhtml";
> 
> from the stylesheet decleration, I notice that <br/> tags and 
> <hr/> tags
> end up like this: <br> and <hr>.  Including it results in the 
> <html> tag
> looking like this:
> <HTML xmlns="http://www.w3.org/1999/xhtml";>
> 
> and the <br> and <hr> tags are now <br/> and <hr/> in the result.
> 
> Is this all confirmed and normal behaviour?

Yes. The output method defaults to HTML if the outermost element in the
result tree is an <html> element in the null namespace. And whether or not
the output method is HTML, elements in a non-null namespace are serialized
using XML rules, so an empty <br> element in the XHTML namespace is written
as <br/>.
> 
> I guess I don't understand when:
> <xsl:output method="html" encoding="??????????"/>
> The encoding has any effect on the outcome.
> 

The encoding parameter affects the outcome if (a) you are using the XSLT
processor to do the serialization (and not, say, the DOM save method), and
(b) the destination of the output is a byte stream rather than a character
stream. A common mistake for Microsoft users is to serialize to a character
stream, in which case the final encoding is outside the control of the XSLT
processor.

Michael Kay

Current Thread