Question

I'm trying to output paul irish' conditional comments around the html tag, in a page generated by xslt

<!--[if lt IE 7 ]> <html lang="en" class="no-js ie6"> <![endif]-->

etcetera. This works

<xsl:comment>[if lt IE 7]&gt; &lt;html class="no-js ie6"&gt; &lt;![endif]</xsl:comment> 

but unfortunately, some parsers decide to put the doctype declaration before the first real element, and after any preceding xml comments. xsltproc puts the doctype before the comments, saxon puts it after the comments. its apparently unspecified what the good behaviour is, but ie wants the doctype to be the first thing in the page, period.

In short, I'm trying to find a way to make saxon output a doctype before any comments. any ideas ?

Was it helpful?

Solution

Saxon is right, the specifications are clear: when serializing the result document the doctype declaration must be put immediately before the first element. This is specified in both XSLT 1.0 and XSLT 2.0:

If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element.

To solve this you can add manually the doctype declaration in your document, using the xsl:text element with the disable-output-escaping attribute set to yes. For example you can output a standard HTML5 doctype, without any public identifier, which would be otherwise impossible to do in XSLT.

<xsl:text disable-output-escaping="yes">&lt;!DOCTYPE html></xsl:text>

OTHER TIPS

Eventually I didnt do this .. I ended up doing it in javascript

if ($.browser.msie) {
    if ($.browser.version<9) $('html').addClass('lt-ie9');
    if ($.browser.version<8) $('html').addClass('lt-ie8');
    if ($.browser.version<7) $('html').addClass('lt-ie7');

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top