IE conditional comments & XSLT
While I was building my site in Symphony, I had a bit of a learning curve with XSLT and even simple, little things were a challenge. One of those dumb, little things were getting Internet Explorer conditional comments to output in my XHTML. It took a bit of Googling, but I figured it out.
Below is the code I wanted to output
<!--[if IE]><link rel="stylesheet" href="http://www.joshnichols.com/workspace/css/ie.css" type="text/css" media="screen, projection"><![endif]-->
I tried wrapping it with <xsl:comment> but since there were incomplete nodes inside from the IE specific comment, the XML wasn’t well formed. After searching for an answer on Google, I found out about XML CDATA. It keeps anything between <![CDATA[ and ]]> from being parsed. I added that bit of code and I was able to pass the conditional comment through.
Here’s the final working code
<xsl:comment><![CDATA[[if IE]><link rel="stylesheet" href="http://www.joshnichols.com/workspace/css/ie.css" type="text/css" media="screen, projection"><![endif]]]></xsl:comment>
Anytime you want to pass commented out code that isn’t well formed XML through the XML transformer, you’ll need XML CDATA.
Comments // What has been said about this entry
I found some discussion on this topic at the Overture Forum with some more information. Also, www.nickfitz.co.uk has a nice writeup on the topic.