Peter West lists(_at_)pbw(_dot_)id(_dot_)au
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
dinsdag 24 juni 2014 10:29
<xsl:strip-space elements="*"/>
<xsl:output method="xhtml" />
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><!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="󠀁" string="<!DOCTYPE html>"/>
</xsl:character-map>
<xsl:strip-space elements="*"/>
<xsl:output method="xhtml" use-character-maps="doctype"/>
<xsl:template match="/">
<xsl:text>󠀁</xsl:text>
<xsl:apply-templates/>
</xsl:template>
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 "󠀁 ">
]>
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.
Cheers,
Abel
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--