internet-explorerxsltconditional-comments

Creating conditional comments with XSLT?


I want to create conditional comments in XSLT.

But when I use this:

<!-- [If IE7] [endif] -->

in an <xsl:comment>, XSLT removes it from the output when it is rendered.

Is there any way to create conditional comments in XSLT?


Solution

  • Simply use an <xsl:comment> tag and include your comment within the tag.

    For example:

    <xsl:if test="@id = '1'">
      <xsl:comment>
        <![CDATA[[if IE]><![endif]]]>
      </xsl:comment>
    </xsl:if>
    

    Taming Your Multiple IE Standalones is a great article on this subject.