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;“.

No comments Digg this

No comments yet. Be the first.

Leave a reply