Skip to content

Instantly share code, notes, and snippets.

@xpathr
Created May 10, 2012 14:40
Show Gist options
  • Select an option

  • Save xpathr/2653501 to your computer and use it in GitHub Desktop.

Select an option

Save xpathr/2653501 to your computer and use it in GitHub Desktop.
IE Conditional Comments in XSLT by MrBlank
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Name: IE Conditional Comments in XSLT
Version: 1.0
Author: Josh Nichols <mrblank@gmail.com>
URL: http://www.joshnichols.com/
Source: Credit goes to Nick Fitzsimons: http://www.nickfitz.co.uk/2005/10/27/ie-conditional-comments-in-xslt-10/
Description:
I'm adding this Utility to www.symphony-cms.com because I use it on every Symphony site I build and think it would help people new to Symphony.
I also added the meta tag to force IE to render in edge renderng mode and keep the IE7 compatibility mode button away.
There is also a simpler way if you want to try this instead (Thanks to michael-e in the forums):
<xsl:comment><![CDATA[[if IE 6]><link rel="stylesheet" type="text/css" href="]]><xsl:value-of select="$root"/><![CDATA[/workspace/assets/css/ie6.css" media="screen" /><![endif]]]></xsl:comment>
About IE Conditional comments: http://msdn.microsoft.com/en-us/library/ms537512.aspx
About IE8 standards mode: http://msdn.microsoft.com/en-us/library/cc817574.aspx
-->
<!-- Begin with your basic XHTML page structure -->
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
<xsl:template match="/">
<html>
<head>
<!-- Meta tag to force IE to render in edge rendering mode (see above) -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- Call the template that will output IE conditional comments -->
<xsl:call-template name="conditional-comment">
<!-- The 'qualifier' is the version of IE you want to target this is any version less than IE8 -->
<xsl:with-param name="qualifier" select="'lte IE 8'"/>
<!-- The 'contentRTF' contains the link tag with attributes -->
<xsl:with-param name="contentRTF">
&lt;link rel="stylesheet" type="text/css" href="{$workspace}/css/ie.css" /&gt;
</xsl:with-param>
</xsl:call-template>
</head>
<body>
<!-- Page content -->
<!-- You might want to use <xsl:apply-templates/> here and use this utiltiy as a base for your 'master.xsl'-->
</body>
</html>
</xsl:template>
<!-- The template that prints the IE conditional comment with the paramaters above -->
<xsl:template name="conditional-comment">
<xsl:param name="qualifier"/>
<xsl:param name="contentRTF"/>
<xsl:comment>
[if <xsl:value-of select="$qualifier"/>]<![CDATA[>]]>
<xsl:copy-of select="$contentRTF" />
<![CDATA[<![endif]]]>
</xsl:comment>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment