Copied to clipboard

Flag this post as spam?

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


  • Geoff Stokes 19 posts 38 karma points
    Sep 23, 2011 @ 09:40
    Geoff Stokes
    0

    Looping error causing nesting

    Hi all,

    I have a macro which selects events from pdcalendar and displays a nicely formatted list of upcoming ones.

    We recently ran into an issue whereby it will, after displaying about 11 events, for some reason, skip over a closing <div> tag and cause the next item to appear within the previous. This then occurs approximately every four items.

    I can't see anything in my code which would cause this, so I'm at a loss.

    <xsl:for-each select="$currentPage/Event [umbraco.library:DateGreaterThanOrEqualToday(./pdcalendarevent/pdcalendarevent/pdcstart)]">
      <xsl:sort select="current()/pdcalendarevent/pdcalendarevent/pdcstart"/>
      
      <div class="event_1_main">
        <div class="event_img">
          <xsl:copy-of select="$currentPage/data[@alias='eventImage/umbracoFile']"/>
          <href="{umbraco.library:NiceUrl(current()/@id)}"><img src="{umbraco.library:GetMedia(current()/eventImage, true())/umbracoFile}" alt="" border="0"/></a>
        </div>
        <div class="event_right_part">
          <h2 class="event_title"><xsl:value-of select="current()/mainContentTitle"/></h2>
          <div class="event_text">
            <strong><xsl:value-of select="umbraco.library:FormatDateTime(current()/pdcalendarevent/pdcalendarevent/pdcstart, 'D')"/></strong>
            <br />
            <xsl:value-of select="umbraco.library:TruncateString(current()/eventDescription, number(275), '...')" disable-output-escaping="yes"/>
          </div>
          <div class="viewmore_btn"><href="{umbraco.library:NiceUrl(current()/@id)}">More Information</a></div>
        </div>
      </div>
    </xsl:for-each>
  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Sep 23, 2011 @ 11:04
    Warren Buckley
    1

    Hey Geoff,
    If your logic causes an empty <div></div> to be created like so without any inner content the XSLT will create the div like so <div /> which cause browser inconsistencies.

    So the easiest way is to switch the XSLT file from XML to HTML at the top of the file.

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

    Needs changing to

    <xsl:output method="html" omit-xml-declaration="yes"/>
  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 23, 2011 @ 11:08
    Douglas Robar
    0

    Hi, Geoff,

    As Warren says, some browsers don't render a self-closed <div /> gracefully. You've got two options:

    1. put an <xsl:if> around the whole thing so no <div> tags are output unless there is some content in the output (best option)
    2. change output method to html (quick but not great option)
    To understand why I don't like the second option, check out my blog post at http://blog.percipientstudios.com/2009/4/11/anatomy-of-an-umbraco-xslt-file.aspx, in particular the section on Line 10, XSL Output. You'll learn the ramifications of using html output can have on your no longer being xhtml valid.
    cheers,
    doug. 

     

  • Geoff Stokes 19 posts 38 karma points
    Sep 26, 2011 @ 04:52
    Geoff Stokes
    0

    I don't understand where the issue is, there is no reason there should be an empty tag, and changing the output method does not fix the issue.

  • Warren Buckley 2106 posts 4836 karma points MVP 7x admin c-trib
    Sep 26, 2011 @ 09:49
    Warren Buckley
    0

    Hey Geoff,
    Can you provide more speicifcs to the problem.
    As in which part of the code is causing the empty <div> to be outputted to the page?

    Then we can try and figure out what is causing it.

  • Geoff Stokes 19 posts 38 karma points
    Sep 29, 2011 @ 03:03
    Geoff Stokes
    0

    Hey guys,

    Turns out it was a completely different mistake.

    umbraco.library:TruncateString(current()/eventDescription, number(275), '...')

    Operated on rich-text content, meaning there were potentially HTML tags being opened, but never closed. This has now been corrected to;

    umbraco.library:TruncateString(umbraco.library:StripHtml(current()/eventDescription), number(275), '...')

    And is working correctly.

    -Geoff

Please Sign in or register to post replies

Write your reply to:

Draft