Copied to clipboard

Flag this post as spam?

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


  • Ciprian 17 posts 38 karma points
    Sep 21, 2010 @ 16:24
    Ciprian
    0

    Odd error in macro occuring only one out of 10 times

    Hey guys!

    I have a macro that outputs some html but the thing is that one out of 10 times or so it really messes up the code.

    Here's the part of the macro that does the outputing:

    <xsl:for-each select="$ParentNode/News [@isDoc and contains(./date,$searchDate)]">
        <xsl:sort select="./date" order="descending"/>
        <xsl:if test="position() &gt; $itemsPerPage*($page -1) and position() &lt;= $itemsPerPage*($page)">
            <div class="ShortNews">
              <a>
                <xsl:attribute name="href">
                  <xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                </xsl:attribute>
                <div class="ImgHolder">
                  <xsl:call-template name="Image">
                    <xsl:with-param name="imgAlias" select="'newsImage'"/>
                    <xsl:with-param name="imgHeight" select="92"/>
                    <xsl:with-param name="currentPage" select="."/>
                  </xsl:call-template>
                </div>
                <h3><xsl:value-of select="./title"/></h3>
                <p class="Date"><xsl:value-of select="umbraco.library:FormatDateTime(./date,'dd.MM.yyyy')"/></p>
                <p><xsl:value-of select="./shortDescription"/></p>
              </a>
          </div>
          <xsl:if test="position()=($itemsPerPage*($page -1)+1)">
            <xsl:text disable-output-escaping="yes"><![CDATA[<div class="Clear"></div>]]></xsl:text>
          </xsl:if>
        </xsl:if>
      </xsl:for-each>

    And here's what it outputs when it's ok:

    <div class="ShortNews">
      <a href="link.aspx">
        <div class="ImgHolder">
          <img src="does%20work_files/ImageGen.jpg">
        </div>
        <h3>Here's the news 2</h3>
        <p class="Date">15.09.2010</p>
        <p>Content</p>
      </a>
    </div>

    And here's what it outputs from time to time:

    <div class="ShortNews">

    <a href="link.aspx">

    </a>

    <div class="ImgHolder">

    <a href="link.aspx"><img src="doesn%27t%20work_files/ImageGen_005.jpg"></a>

    </div>

    <h3><a href="link.aspx">Here's some more news</a></h3>

    <p class="Date"><a href="link.aspx">12.09.2010</a></p>

    <p><a href="link.aspx">Content</a></p>

    </div>

    As you can see it wraps every one of the inner elements in the <a> tag. And this only happens from time to time.

    Thanks a bunch,

    Ciprian

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    Sep 21, 2010 @ 21:13
    Lee Kelleher
    0

    Hi Ciprian,

    Curious, how are you viewing the HTML output? Which web-browser? I'm guessing its via Chrome's Developer Tools?

    Try viewing the raw HTML via view-source - or a different web-browser?

    My thinking is that Chrome might not like that you've wrapped an inline tag <a> around a block-level tag (like <div> or <h3>) so it trying to re-render the HTML accordingly.  But that's just a guess!

    Cheers, Lee.

  • Ciprian 17 posts 38 karma points
    Sep 22, 2010 @ 08:59
    Ciprian
    0

    Thanks for the reply Lee!

    This error only appears in Mozilla Firefox and it causes pretty nasty layout problems. If I try to look at the source via View Source everything's fine, but the layout problem is still there. The only way to really see it is to save the page by Save Page As... and then looking at the source.

    The odd thing is that this is in a for-each and there are more than one elements like this one on a page. Only one of them gets messed up like this and it's only once in a while.

    Any ideas?

    Ciprian

  • Ciprian 17 posts 38 karma points
    Sep 22, 2010 @ 10:33
    Ciprian
    0

    I solved the issue. The thing was that I was calling a template from the macro and aparently sometimes it didn't parse the XML properly into HTML and this caused the problem.

    I changed the output of the template from XML to HTML and the problem stopped.

    Should this be reported as a bug?

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    Sep 22, 2010 @ 10:48
    Lee Kelleher
    0

    Hi Ciprian,

    It's not a bug.  It sounds like part of the content was missing - and it self-closed a tag... which is perfectly valid XML, but not valid (x)HTML (depending on the tag).

    By changing the output from XML to HTML, you have resolved that issue because the empty tag does not self-close.  Keep in mind that if you need to use valid self-closing tags (like <img/>, <hr/>, <br/>), then those might render incorrectly ... i.e. <img></img>

    Usually the way we get around the empty/self-closing tags is to insert a HTML comment into it, i.e.

    <p>
        <xsl:value-of select="shortDescription" />
        <xsl:comment />
    </p>

    So that will render as <p><!----></p> instead of <p/> ... which would make most web-browsers bork!

    Cheers, Lee.

  • Ciprian 17 posts 38 karma points
    Sep 22, 2010 @ 11:37
    Ciprian
    0

    Hey,

    But that's the thing, the <a> tag was never empty. There was always content in it and in stead of just closing it once it actually put it inside of all the tags it was supposed to contain.

    So from something like this:

    <a>
      <h3>Title</h3>
      <p>Stuff</p>
    </a>

    it went to this:

    <a></a>
      <h3>
        <a>Title</a>
      </h3>
    <p>
      <a>Stuff></a>
    </p>

    Thanks,

    Ciprian

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    Sep 22, 2010 @ 11:50
    Lee Kelleher
    0

    Hi Ciprian,

    Just noticed this... what's going on in the "Image" template? From when you call:

    <xsl:call-template name="Image"> ...

    It appears to not be closing the <img> tag?

    <img src="does%20work_files/ImageGen.jpg">

    Which is fine for HTML 4 ... but if Firefox is expecting XHTML, then it might try to compensate and render those additional <a> tags? (I'm guessing a bit here)

    Is your website publicly available? I wouldn't mind taking a little look at the HTML myself.

    Cheers, Lee.

  • Ciprian 17 posts 38 karma points
    Sep 22, 2010 @ 13:17
    Ciprian
    0

    Here's the code to the Image macro:

    <xsl:output method="html" omit-xml-declaration="yes"/>
        
    <xsl:template name="Image">
      <xsl:param name="imgAlias"/>
      <xsl:param name="imgWidth"/>
      <xsl:param name="imgHeight"/>

    <xsl:param name="currentPage"/>

    <!-- start writing XSLT -->
    <xsl:variable name="imageAlias">
      <xsl:value-of select="$imgAlias" />
    </xsl:variable>
    <xsl:variable name="Width">
      <xsl:value-of select="$imgWidth" />
    </xsl:variable>
    <xsl:variable name="Height">
      <xsl:value-of select="$imgHeight" />
    </xsl:variable>

      <xsl:variable name="media">
        <xsl:value-of select="$currentPage/*[name() = $imageAlias]"/>
      </xsl:variable>
      <img>
        <xsl:attribute name="src">
          <xsl:text>/umbraco/ImageGen.ashx?image=</xsl:text>
          <xsl:value-of select="$media"/>
          <xsl:if test="$Width !=''">
            <xsl:text>&amp;width=</xsl:text>
            <xsl:value-of select="$Width"/>
          </xsl:if>
          <xsl:if test="$Height !=''">
            <xsl:text>&amp;height=</xsl:text>
            <xsl:value-of select="$Height"/>
          </xsl:if>
        </xsl:attribute>
      </img>

    </xsl:template>

    It uses imagegen to resize an image based on recived height, width and alias.

    You can see the page here: http://nksplit.mplus.hr/arhiva.aspx I put the output method of Image template back to xml so if you play with the 1, 2 buttons for a while you will see a layout problem in mozilla.

    Thanks a bunch,

    Ciprian

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    Sep 22, 2010 @ 13:30
    Lee Kelleher
    0

    Hey Ciprian, just tried paging between the 1, 2 paging buttons for a while - but didn't get to see any errors.

    Not sure if it makes a difference, but I'm using Firefox 3.6.10.

    Cheers, Lee.

  • Ciprian 17 posts 38 karma points
    Sep 22, 2010 @ 13:56
    Ciprian
    1

    I've been trying it too and no difference, it just went away... I don't get it.

    I have the same version of Firefox.

    Maybe changing the output method from xml to html and back did something, maybe it was cached somewhere.

    Well thanks for the help, it's good that it's gone. I just hope it doesn't show up anymore.

    Ciprian

  • psiho 101 posts 96 karma points
    Nov 01, 2010 @ 21:49
    psiho
    0

    Back to this again.. I took over from Ciprian and now again ran into same problem. It's driving me mad. Website is almost done and client noticed the same issue again.

    To reproduce it go to: http://nksplit.mplus.hr/arhiva.aspx and use paging to browse news one by one. It is almost certain that you will not get by page 10 before problem appears. You will notice it by looking at thumbnails of 4 news on a page - usually last one drops down below frame and title/text next to it is nov visible anymore. Click view/source or use firebug and you'll notice that A tag is opened and closed mayn times instead of only once. Now, just click refresh in your browser and it is gone! Next time error is on some other page.

    I managed to reproduce it only in Firefox, but several older version and latest one too.

     

  • psiho 101 posts 96 karma points
    Nov 02, 2010 @ 22:47
    psiho
    0

    Going crazy here. Same thing is now happening on another place (http://nksplit.mplus.hr/galerija.aspx). Also, changing output to HTML as mentioned above does not help anymore.

    Further, inspecting code with firebug now showed me that A tag was once even given class "_moz-rs-heading"!? Ther's no class lik ethat anywhere in my code. Firefox is just behaving very strange with XSL outpu. Further investigation of this showed me link with explanation of Firefox behaviour when A tak wraps arround HTML5 element (http://oli-studio.com/bugs/mozilla/block-level-links.html) but I'm not wrapping HTML5 element but HTML4 element.

  • Lee Kelleher 4024 posts 15833 karma points MVP 13x admin c-trib
    Nov 03, 2010 @ 09:47
    Lee Kelleher
    0

    Hey psiho,

    Its not just related to HTML5, but that you have block-level elements (e.g. <div> tags) inside inline-level elements (e.g. <a> tags). Since that isn't valid in XHTML - which is the DocType you are using ... then Firefox tries to compensate by re-structuring the rendered mark-up.

    You'll need to remove the <div>s from your <a> tags ... and recreate the style with CSS. Using "display:block" on the <a> tags should work.

    Cheers, Lee.

  • psiho 101 posts 96 karma points
    Nov 05, 2010 @ 08:47
    psiho
    1

    we redesigned it and overlayed A over DIV:

    <div class="ShortNews">
    <a href="something.aspx">&nbsp;</a>
    <div class="ImgHolder">
    <img src="something.gif" />
    </div>
    <h3>Title goes here </h3>
    <p class="Date">03.11.2010 </p>
    <p>Content goes here</p>
    </div>

    instead of:

    <div class="ShortNews">
    <a href="something.aspx">
    <div class="ImgHolder">
    <img src="something.gif" />
    </div>
    <h3>Title goes here </h3>
    <p class="Date">03.11.2010 </p>
    <p>Content goes here</p>
    </a>
    </div>

    ... with some CSS that makes A a display:block and overlay completze DIV, so onMouseOver DIV changes background color. This is solved. Ciprian plese mark this thread solved.

Please Sign in or register to post replies

Write your reply to:

Draft