Created
July 24, 2012 12:42
-
-
Save eerohele/3169736 to your computer and use it in GitHub Desktop.
An XSLT stylesheet for adding Paul Irish's conditional IE classes to an XHTML document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<xsl:stylesheet version="2.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xhtml="http://www.w3.org/1999/xhtml"> | |
<xsl:output method="xml" encoding="utf-8" indent="no" omit-xml-declaration="no"/> | |
<xsl:variable name="newline"><xsl:text> | |
</xsl:text></xsl:variable> | |
<xsl:template match="xhtml:html"> | |
<xsl:value-of select="$newline"/> | |
<xsl:text disable-output-escaping="yes"> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
</xsl:text> | |
<xsl:value-of select="$newline"/> | |
<xsl:comment>paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/</xsl:comment> | |
<xsl:value-of select="$newline"/> | |
<xsl:comment>[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="<xsl:value-of select="@lang"/>"> <![endif]</xsl:comment> | |
<xsl:value-of select="$newline"/> | |
<xsl:comment>[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="<xsl:value-of select="@lang"/>"> <![endif]</xsl:comment> | |
<xsl:value-of select="$newline"/> | |
<xsl:comment>[if IE 8]> <html class="no-js lt-ie9" lang="<xsl:value-of select="@lang"/>"> <![endif]</xsl:comment> | |
<xsl:value-of select="$newline"/> | |
<xsl:text disable-output-escaping="yes"><!--[if gt IE 8]><!--></xsl:text> | |
<html class="no-js"> | |
<xsl:apply-templates select="@*"/> | |
<xsl:text disable-output-escaping="yes"><!--<![endif]--></xsl:text> | |
<xsl:value-of select="concat($newline, $newline)"/> | |
<xsl:apply-templates select="*"/> | |
</html> | |
</xsl:template> | |
<xsl:template match="xhtml:script"> | |
<xsl:variable name="begin-cdata"> | |
<xsl:text> | |
//<![CDATA[</xsl:text> | |
</xsl:variable> | |
<xsl:variable name="end-cdata"> | |
<xsl:text> | |
//]]> | |
</xsl:text> | |
</xsl:variable> | |
<xsl:copy> | |
<xsl:apply-templates select="@*"/> | |
<xsl:value-of select="$begin-cdata" disable-output-escaping="yes"/> | |
<xsl:value-of select="."/> | |
<xsl:value-of select="$end-cdata" disable-output-escaping="yes"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="node() | @*"> | |
<xsl:copy> | |
<xsl:apply-templates select="@* | node()"/> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment