Copied to clipboard

Flag this post as spam?

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


  • JacoboPolavieja 62 posts 84 karma points
    Aug 27, 2010 @ 17:22
    JacoboPolavieja
    0

    Google AdSense script makes XSLT to not work

    Hello!

     

    I have been trying to insert some ads on my website. I have Google AdSense's script, but when I insert it and try to display the page, it displays till the point where the script is put, and nothing below where the script is put (although the HTML is there if I browse it with Firefox!).

     

    I have tried the same on a static page locally and it works, but seems like the moment I put it in my XSLT file, it makes everything below disappear.

    The script is, just in case:

          <script type="text/javascript">
            <!--
                google_ad_client = "pub-XXXXXXXXXX";
                /* 728x15, created 8/27/10 */
                google_ad_slot = "XXXXXX";
                google_ad_width = 728;
                google_ad_height = 15;
                //-->
          </script>
          <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
          </script>

    I have placed it in several areas of the page... inside a div, outside a div, etc... but the result is the same.

     

    Any idea why this can be happening? Thanks!

  • jc 64 posts 101 karma points
    Aug 27, 2010 @ 17:41
    jc
    1

    Is it getting stripped out because of the comment tags? Will this work?

    <script type="text/javascript">
        //<![CDATA[
        google_ad_client = "pub-XXXXXXXXXX";
        /* 728x15, created 8/27/10 */
        google_ad_slot = "XXXXXX";
        google_ad_width = 728;
        google_ad_height = 15;
        //]]>
    </script>
  • JacoboPolavieja 62 posts 84 karma points
    Aug 27, 2010 @ 18:21
    JacoboPolavieja
    0

    Hi jc and thanks for answering!

     

    First I realized about the closing tags and XSLT. It was in fact closing the scripts with "/>" instead of "</script>".

    Having solved that I know see I can't get it to display the comment on the first javacript properly. With your solution, I get nearly what I need. This is the output:

    <script type="text/javascript">
    //
    google_ad_client = "pub-XXXXXXXXXX";
    /* 728x15, created 8/27/10 */
    google_ad_slot = "XXXXXX";
    google_ad_width = 728;
    google_ad_height = 15;
    //</script>

    I would need to substitute those "//" with respective "<!--" and "//-->", but I don't know how to do that as if I put them explicitly, XSLT takes them as comments and doesn't include them, which I need. Any idea?


    Thanks a lot!

  • FreedomChicken 12 posts 33 karma points
    Aug 27, 2010 @ 18:33
    FreedomChicken
    0

    you can just try to wrap the entire thing in a CDATA

    <![CDATA[
          <script type="text/javascript">
                google_ad_client = "pub-XXXXXXXXXX";
                /* 728x15, created 8/27/10 */
                google_ad_slot = "XXXXXX";
                google_ad_width = 728;
                google_ad_height = 15;
          </script>
          <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
          </script>
    ]]>

    It may aslo be that since there is no data between your second Script tag and closing of that tag it is not rendering the page properly and trying to put everything inside of that script tag. That can be solved by:

    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">&nbsp;</script>

  • JacoboPolavieja 62 posts 84 karma points
    Aug 27, 2010 @ 18:48
    JacoboPolavieja
    0

    Hi FreedomChicken!

    Trying your solution it outputs:

    &lt;script type="text/javascript"&gt;&lt;!--
    google_ad_client = "pub-8423653572831951";
    /* 728x15, created 8/27/10 */
    google_ad_slot = "5173549697";
    google_ad_width = 728;
    google_ad_height = 15;//--&gt;&lt;/script&gt

    I have been able to solve it using:

                <script type="text/javascript">
                  <xsl:text disable-output-escaping="yes">&lt;!--</xsl:text>
                  <![CDATA[
    google_ad_client = "pub-8423653572831951";
    /* 728x15, created 8/27/10 */
    google_ad_slot = "5173549697";
    google_ad_width = 728;
    google_ad_height = 15;
        //]]><xsl:text disable-output-escaping="yes">--&gt;</xsl:text>
                </script>

    I know it's not too elegant... but it's the only thing I've been able to come up with to right now =).

    If anybody has something better... glad to hear about it.

    Thanks both for helping! Cheers!

  • FreedomChicken 12 posts 33 karma points
    Aug 27, 2010 @ 19:28
    FreedomChicken
    1

    Oh yeah, forgot it does that. Another solution could be to simply throw it into aDictionary item and reference it like:


        <xsl:value-of select="umbraco.library:GetDictionaryItem('googleScript')" disable-output-escaping="yes" />

     

  • FreedomChicken 12 posts 33 karma points
    Aug 27, 2010 @ 19:30
    FreedomChicken
    0

    Oh yeah, forgot it does that. Another solution could be to simply throw it into aDictionary item and reference it like:


        <xsl:value-of select="umbraco.library:GetDictionaryItem('googleScript')" disable-output-escaping="yes" />

     

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Aug 27, 2010 @ 23:56
    Chriztian Steinmeier
    0

    Hi Jacobo,

    The "correct" (and clean/elegant) way to do this, is to use the xsl:comment instruction:

    <script type="text/javascript">
    <xsl:comment><![CDATA[
        google_ad_client = "pub-XXXXXXXXXX";
        /* 728x15, created 8/27/10 */
        google_ad_slot = "XXXXXX";
        google_ad_width = 728;
        google_ad_height = 15;
    //]]></xsl:comment>
    </script>
    <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><xsl:comment /></script>
    
    (The empty comment inside the second script element is to prevent getting the self-closing script tag).

    /Chriztian 

Please Sign in or register to post replies

Write your reply to:

Draft