【问题标题】:Conditional comment in XSL not workingXSL 中的条件注释不起作用
【发布时间】:2013-01-22 20:06:30
【问题描述】:

我在 XSL 中添加了条件注释,例如

 <xsl:comment>          
    <![CDATA[
       [if IE]>
         <script type="text/javascript">
             registerDisplay = firstChild.currentStyle.display;
         </script>
       <![endif]            
     ]]>
 </xsl:comment>

我在 IE 中没有看到我的 html 源代码。任何帮助表示赞赏。

【问题讨论】:

  • 当我使用 xsltproc 运行时,这对我来说效果很好(尽管您可能希望删除注释标记和条件内容之间的空白,即&lt;xsl:comment&gt;&lt;![CDATA[[if IE]&lt;![endif]]]&gt;&lt;/xsl:comment&gt;)。请记住,当您在浏览器中打开带有 &lt;?xml-stylesheet 指令的 XML 文件时,查看源代码将为您提供原始 XML,而不是 XSLT 生成的 HTML。

标签: internet-explorer xslt conditional-comments


【解决方案1】:

如果您对 xsl:comment 不满意,我认为您也可以使用

<xsl:text disable-output-escaping="yes"><![CDATA[<!--[if IE]>
     <script type="text/javascript">
         registerDisplay = firstChild.currentStyle.display;
     </script>
   <![endif]-->]]>
</xsl:text>

【讨论】:

    猜你喜欢
    • 2014-10-08
    • 2014-04-02
    • 2012-05-07
    • 2012-01-25
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    相关资源
    最近更新 更多