IE7 Stylesheet Only for XSL Document

How to add IE7 and below stylesheet for XSL page? I tried adding it to the template for header information as follows:

<xsl:template name="header"> <!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> <![endif]--> </xsl:template> 

And the conditional code will never be executed in my document, although I use the same snippet in the documents for HTML only, and it works great. What gives?

+6
source share
3 answers

A comment will be considered by the parser as a comment in XSL and will be removed from the generated HTML code.

If you want to generate a comment in your HTML, you need to enclose it in a CDATA block, so it will be interpreted by the XSL parser as plain text that will be copied to the destination document verbatim.

The code will look like this:

 <![CDATA[ <!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> <![endif]--> ]]> 

Everything between <![CDATA[ and ]]> will be treated as plain text.

Hope this should answer your question.

However, if at all possible, I would suggest the best solution here is to abandon IE7 support. Usage statistics for this have fallen across the floor in the last six months or so - it's almost as low as IE6; hardly anyone is still using it. I understand that in some cases you may not have a choice, but if you have a choice, my advice is to give it up.

[EDIT]

Well, after further research, it seems that you are right: a simple CDATA block does not go out of its way (despite claims to the contrary in many places).

Instead, you need to use <xsl:comment> to generate the HTML comment in the output. Doing this using conditional comment syntax gets pretty messy, and you probably still have to use CDATA.

The best example I can find is here: http://getsymphony.com/download/xslt-utilities/view/21798/

As you can see, this is quite a bit of code.

A short version (without flexibility) might look like this:

 <xsl:comment> [if lte 7<![CDATA[>]]> <link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> <![CDATA[<![endif]]]> </xsl:comment> 

Hope this helps. Sorry, the original answer was incomplete.

+3
source

Here's one proven way to do this - this is one of the rare cases where DOE is useful :

 <xsl:text disable-output-escaping="yes"> &lt;!--[if lte IE 7]> &lt;link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> &lt;![endif]--> </xsl:text> 

Full example :

 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/*"> <xsl:text disable-output-escaping="yes"> &lt;!--[if lte IE 7]> &lt;link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> &lt;![endif]--> </xsl:text> <p> Done. </p> </xsl:template> </xsl:stylesheet> 

When this conversion is applied to any XML document (not used), the desired, correct result is obtained :

 <!--[if lte IE 7]> <link rel="stylesheet" type="text/css" href="/rcm/verisign/style/2012/ie7.css"/> <![endif]--> <p> Done. </p> 
+1
source

You have:

 <!--[if lte IE 7]> 

It should be:

 <!--[if lt IE 7]> 
-1
source

Source: https://habr.com/ru/post/922082/


All Articles