[xsl] Using xsl:output in browsers, was: Re [xsl] XHTML html validation

Subject: [xsl] Using xsl:output in browsers, was: Re [xsl] XHTML html validation
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Mon, 19 Feb 2007 21:15:21 +0100
Braum|ller wrote:
Hi Abel,

i read your comment about

<snip>
Can you advice me the correct declaration for client-side, browser-based XSLT,
if i want output either HTML or XHTML ?


I have always used for HTML
<xsl:output method="html" encoding="iso-8859-1" indent="no"/>
or for XHTML
<xsl:output method="xml" encoding="iso-8859-1" indent="no"
  doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
  doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" /

Hi All,


Correct me if I am wrong, but I think there is a little confusion going on in this thread. Owen, a little after this message, goes to some length explaining where the OP may have gone wrong, which is good, but it looks like he's actually answering Hans with the subject of John Steel.

Here's the answer to the OP's question, going close to Owen's remarks: http://www.biglist.com/lists/xsl-list/archives/200702/msg00495.html.

Hans, however, started a new thread, unintentionally I'm sure, about the subject whether or not to use xsl:output, and how, in browser based XSLT (this only occurred to me after reading Hans's second post where he stated that his XSLT is fine, which is not so for John's, yet). Let us keep the subjects a bit separated.

About Hans' question:
I originally stated that using xsl:output has no effect. That is not entirely true. See below:


<xsl:output method="html" indent="yes" />
IE6: dom
FF: dom (type HTMLDocument)

<xsl:output method="text" />
IE6: dom
FF: a string inside the <transformiix:result>
This link tempts to explain this http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations, but I don't have the same experience with IE.


<xsl:output method="xml" />
IE6: dom
FF: dom (type XMLDocument)

For all methods: in FF, you will get the <transformiix:result> root element when the output would otherwise not be legal XML (i.e., when you would otherwise have multiple root nodes etc). See here for more explanations for FF: http://developer.mozilla.org/en/docs/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations

There are subtle differences in the objects returned. I learned the hard way that the safest between browsers seem the output method xml. It does not matter whether you add other output options, as, again, the output is never serialized (and processors that do not serialized are allowed to skip all or part of the xsl:output method).

It did not investigate fully, esp. not for IE6, so the statements above may contain errors. Sorry for that.

For all browsers: when you use a user defined output method, you receive an error. When you do not specify an output method, it is XML (as it should). If you specify an encoding: don't. All browsers support UTF-8 internally, there is no use whatsoever to limit your resulting characters, possibly resulting in erroneous or unexpected behavior.

Cheers,
-- Abel Braaksma
  http://www.nuntia.nl

Current Thread