Conditional Comments in XSLT

I’ve been meaning to blog this for a while having come across the problem on a project last year. When including conditional comments in a page rendered using XSL templates the comment has to be structured in a way that doesn’t break the stylesheet. While this sounds simple it took a few attempts to get a working solution.

<xsl:comment>[if lte IE 6]<![CDATA[>]]>
   &lt;link rel="stylesheet" type="text/css" href="styles.css" /&gt;
<![CDATA[<![endif]]]></xsl:comment>

The comment must be structured inside an <xsl:comment> block which, when rendered to the browser, becomes a standard html comment and the greater than and less than brackets on the stylesheet link itself must be entered using their respective character entity codes “&gt;” and “&lt;“.

About Simon

Pixel pushing front-end designer originally from the UK now in sunny... ok, ok "Windy" Wellington, New Zealand (Home of the mighty WORLD CHAMPION All Blacks ;-)

Speak Your Mind

*

Stop SOPA