0 users online. Create an account or sign in to join them.Users
IE Conditional Comments in XSLT
Browser Target
Description
An easy way to add IE conditional comments for linking to CSS files. Credit goes to Nick Fitzsimons for the solution.
I also added the meta tag to force IE to render in edge rendering mode and keep the IE7 compatibility mode button away. Gist link.
XSLT
View Raw
<?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 <[email protected]>
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">
<link rel="stylesheet" type="text/css" href="{$workspace}/css/ie.css" />
</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>