XML/XSLT conditional comment IE stylesheet

痴心易碎 提交于 2019-12-11 10:38:17

问题


I'm having an issue that I just can't seem to figure out. I built a website not too long ago in HTML and have recently integrated Symphony CMS and have had to change everything to XML.

Originally in my head, I had a internet explorer specific stylesheet, the head looked something like this:

<head>
       <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>
       <!--[if IE]>
             <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
             <script src="../js/html5shiv.js"></script>
       <![endif]-->
</head>

Since switching, this conditional comment does no longer work, I've changed it to this but unfortunately, my master.css is getting ignored for Chrome/Firefox etc... It is just loading the ie.css stylesheet for all browsers.

<head>
    <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>                
    <xsl:comment>[if IE]<![CDATA[><!]]></xsl:comment>
          <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
          <script src="../js/html5shiv.js"></script>
    <xsl:comment><![CDATA[<!]]>[endif]</xsl:comment>    
</head>

Sorry I'm fairly new at this and I'm just not sure what I'm doing wrong, I'm guessing I might need some sort of xsl:if comment but just not sure how to go about it really. I just need something that will make chrome/firefox/opera/safari ignore the ie.css stylesheet.

Any help would be greatly appreciated! Thanks


回答1:


Just use one xsl:comment and wrap all of the contents in <![CDATA[]]>...

    <head>
        <link rel="stylesheet" href="../css/master.css" type="text/css" media="screen"></link>
        <xsl:comment><![CDATA[[if IE 6]>
         <link rel="stylesheet" type="text/css" href="../css/ie.css"></link>
         <script src="../js/html5shiv.js"></script>
   <![endif]]]></xsl:comment>
    </head> 



回答2:


Use a template to allow conditional comments to be defined programmatically:

<xsl:template name="conditionalComment">
    <xsl:param name="qualifier" select="'IE'"/>
    <xsl:param name="contentRTF" select="''" />


    <!--Use entity variables to allow invalid XML output from an XSLT processor-->
    <xsl:comment>[if <xsl:value-of select="$qualifier"/>]<![CDATA[>]]>
    <!--Use copy-of rather than value-of to preserve tag delimiters-->
        <xsl:copy-of select="$contentRTF" />
    <!--Use CDATA to output raw characters-->
        <![CDATA[<![endif]]]></xsl:comment>

</xsl:template>

The template takes two parameters:

<xsl:call-template name="conditionalComment">
    <!--Conditional check parameter-->
    <xsl:with-param name="qualifier" select="'lte IE 6'"/>
    <!--Stylesheet parameter-->
    <xsl:with-param name="contentRTF">
        &lt;link rel="stylesheet" type="text/css" href="ie-win-fixup.css" /&gt;
    </xsl:with-param>
</xsl:call-template> 

References

  • IE Conditional Comments in XSLT 1.0

  • IE7-only stylesheet for XSL document

  • XSLT Utilities: IE Conditional Comments in XSLT



来源:https://stackoverflow.com/questions/13726792/xml-xslt-conditional-comment-ie-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!