[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Getting epub: namespace into root html element

Subject: Re: [xsl] Getting epub: namespace into root html element
From: "Abel Braaksma (Exselt) abel@xxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 25 Jun 2014 10:56:39 -0000

Peter West lists@xxxxxxxxx <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
dinsdag 24 juni 2014 10:29

<xsl:strip-space elements="*"/> <xsl:output method="xhtml" /> <xsl:template match="/"> <xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html></xsl:text> <xsl:apply-templates/> </xsl:template>

Consider using character maps with XSLT 2.0, instead of disable-output-escaping. D-o-e is not required to be supported by processors and even if it is supported, the specification uses "should" for explaining the workings of d-o-e, which is less strong than a "must", so even if a processor supports it, the way and level it supports it are implementation defined. Specifically, the specification states (see http://www.w3.org/TR/xslt20/#disable-output-escaping):

"Since disabling output escaping might not work with all implementations and can result in XML that is not well-formed, it should be used only when there is no alternative."

In your case, there is an alternative: character maps, which are guaranteed to work across processors in the same way.

Wendell already covered the fact whether or not you should or should not use a doctype. Note that if you can use XSLT 3.0, you can use the HTML5 output method, which will create the HTML 5 doctype for you. If you cannot switch to XSLT 3.0, here's how you can use character maps to achieve the same effect:

<xsl:character-map name="doctype">
<xsl:output-character character="&#xE0001;" string="&lt;!DOCTYPE html>"/>

<xsl:strip-space elements="*"/>
<xsl:output method="xhtml" use-character-maps="doctype"/>

<xsl:template match="/">

I usually use a character from the Unicode Private Use Area, here U+E0001. For readability, I suggest to add a named entity reference as well, something like:

<!DOCTYPE xsl:stylesheet [
<!ENTITY doctype "&#xE0001; ">

which allows you to write <xsl:text>&doctype;</xsl:text> , quite a bit more readable than the numerical entity reference.

Using character maps is a little bit more involved than "just" using d-o-e, but it is more flexible (you can specify different character maps and each (named) output declaration can specify which character maps to use), it is guaranteed to work cross-processor and it will continue to work with future versions of XSLT that may remove the disable-output-escaping feature altogether.


Current Thread