用于XSL文档的仅限IE7的样式表 [英] IE7-only stylesheet for XSL document

查看:148
本文介绍了用于XSL文档的仅限IE7的样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在XSL网页中加入仅限IE7和较低版本的样式表?我试着将它添加到头信息的模板,如:

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

并且条件不会在我的文档中执行,即使我使用相同的代码段文件和它工作正常。什么给了?

解决方案

解析器将该注释看作是XSL中的注释, HTML代码。



如果你想生成一个注释到你的HTML,你需要将它包含在 CDATA 块,因此它将被XSL解析器看作是纯文本,并被逐字复制到目标文档。



代码如下:

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

<![CDATA []]> 将被视为纯文本。



希望这应该回答你的问题。 >

但是,如果可能,我建议最好的解决方案是放弃对IE7的支持。在过去的六个月左右,它的使用统计数据已经下降了 - 现在几乎和IE6一样低;有几乎没有人仍在使用它。



strong>



好的,经过进一步的研究,你似乎是对的:一个简单的 CDATA



相反,您需要使用< xsl: comment> 在输出中生成HTML注释。



我可以找到的最好的例子是: http://getsymphony.com/download/xslt-utilities/view/21798/



如你所见,这是很多代码。



一个简短的版本:

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

希望有帮助。对不起,原始答案不完整。


How do I add an IE7-and-lower-only stylesheet to an XSL page? I tried adding it into the template for header information like so:

<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 never gets executed in my document, even though I use the same snippet in HTML-only documents and it works fine. What gives?

解决方案

The comment will be seen by the parser as a comment in the XSL, and will be dropped from the generated HTML code.

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

The code would 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.

Hopefully that should answer your question.

However, if at all possible, I'd suggest the best solution here would be to drop support for IE7. The usage stats for it have dropped through the floor in the last six months or so - it's almost as low as IE6 now; there's hardly anyone still using it. I appreciate in some cases you may not have a choice, but if you do have a choice, my advice is to drop it.

[EDIT]

Okay, after further research, it seems you're right: a plain CDATA block does escape its output (despite claims to the contrary in many places).

Instead, you need to use <xsl:comment> to generate an HTML comment in the output. Doing this with conditional comment syntax gets quite messy, and you will probably still need to use CDATA.

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

As you can see, it's quite a lot of code.

A short version (without the 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 that helps. Sorry the original answer was incomplete.

这篇关于用于XSL文档的仅限IE7的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆