Skip to main content
Skip to navigation
Blog XML feed

Blog entry archive // Posts from a desiging, gaming, comic-reading nerd

May 20

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.

About this entry

  • Published: May 20, 2008
  • Tags: Symphony, XSLT
  • Comments: 1

← Previous // Next →

Recent entries

Browse the archive →

Comments // What has been said about this entry

Josh
Nov 12, 2008, 1:31pm

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.

Leave a comment // Have something to say?

Comment rules

Real names are preferred. Comments are moderated before being published.