xml, html or xhtml in <xsl:output>: Which is the better choice?

Tags: xml xslt xslt-2.0
By : B.E.
Source: Stackoverflow.com

For historic reasons we have a mixture of

<xsl:output method="xml">


<xsl:output method="html">


<xsl:output method="xhtml">

inside an include-hierarchy of XSL files. Now we want to refactor so all XSL files use the same output method.

In the end we want to produce XHTML-output so I suppose the latter would be the best choice.

But what are the differences between those three output-methods and which would you use for what kind of solution?

Edit: I'm using XSLT 2.0

By : B.E.


As far as I know, there is no method:xhtml to the xsl:output directive in xslt 1.0.

wc3schools agree with this.

As XHTML is an XML dialect, that's what I would use.

If, however you are using xslt 2.0, might as well use xhtml, since that's what you are outputting.

By : Oded

I found the answer by reading the XSLT 2.0 specification (XSLT 2.0 and XQuery 1.0 Serialization).

Given an empty instance of an XHTML element whose content model is not EMPTY (for example, an empty title or paragraph) the serializer MUST NOT use the minimized form. That is, it MUST output

By : B.E.

HTML will serialize as HTML, so the output may not be well-formed XML. If you are only sending to browsers and don't care about being able to parse as XML then that may work for you.

XML will serialize as XML, so the output will be well-formed, but you may run into some issues with browsers using the output. Small things, like self closing

This video can help you solving your question :)
By: admin