Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shannon 148 posts 171 karma points
    Feb 11, 2011 @ 00:34
    Shannon
    0

    Using xsl:if doesn't include closing tag

    Trying to use the following code to insert a google ad inside of a blog roll

    <xsl:if test="position() = 3"><object data="/frontpage_blogroll_center_top_728x90" width="735" height="95"  ></object></xsl:if> 

    For some reason the closing tag </object> doesn't get rendered in the HTML and causes error. Is there anyway to resolve this?

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Feb 11, 2011 @ 09:27
    Dirk De Grave
    1

    Standard behaviour of xslt, empty tags get 'stripped', need to wrap it inside a CDATA section...

    <xsl:it test="position() = 3">
    <xsl:text><![CDATA[<object data="/frontpage_blogroll_center_top_728x90" width="735" height="95"  ></object>]]></xsl:text>
    </xsl:if>

    Hope this helps.

    Regards,

    /Dirk

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 11, 2011 @ 09:36
    Jan Skovgaard
    1

    Hi Shannon

    I think what Dirk has posted is a good solution to your problem.

    However I think you could also solve it by changing the output method from XML to HTML

    In this line i the XSLT it says pr. default

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    You can change it to

    <xsl:output method="html" omit-xml-declaration="yes"/>

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 11, 2011 @ 09:38
    Chriztian Steinmeier
    2

    Hi Shannon,

    Current best fix for that would actually be to just render a comment inside the <object> element:

    <xsl:if test="position() = 3">
        <object data="/frontpage_blogroll_center_top_728x90" width="735" height="95"><xsl:comment /></object>
    </xsl:if>

    /Chriztian

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 11, 2011 @ 09:41
    Jan Skovgaard
    1

    Nice on Chriztian! It's so obvious I'm feeling ashamed I did not think of that. But hey...lesson learned...once again ;-)

    /Jan

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Feb 11, 2011 @ 09:47
    Chriztian Steinmeier
    0

    @Jan: Your solution is actually really good and I would recommend it, but unfortunately it adds the risk of breaking lots of other stuff for people (think <br>, <link> and <hr> tags etc.) which is a pain for people looking for a fix for the *current* problem :-)

    /Chriztian

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies