Copied to clipboard

Flag this post as spam?

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


  • Frederik T 242 posts 373 karma points
    Apr 27, 2012 @ 10:00
    Frederik T
    0

    Having bodyText inside a link tag, creates several links for each paragraph.

    Sorta difficult to explain the problem in the topic, but here's to hoping it is understandable.

    It's not that big of a problem, but would be nice to fix. On my site i have a simple news section, and the latest news articles are displayed on the front page, which links to the full news article.

    In my xslt, all the information that is displayed like title and bodytext are wrapped in a link tag. But when generated, it splits it up into several link tags, like the header and first paragraph tag in one, and a second in another which looks confusing. Any idea what could cause this? Or do i have to live with it?

    <xsl:param name="currentPage"/>
    <xsl:param name="NumberOfItems" select="/macro/NumberOfItems" />

    <xsl:template match="/">

    <div class="newslist">
      <ul>
        <xsl:for-each select="umbraco.library:GetXmlNodeById(1167)//Nyhed [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:sort select="@updateDate" order="ascending" />
          <xsl:if test="position() &lt;= $NumberOfItems">
            <li>
              <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:choose>
                  <xsl:when test="headerText != ''">
                    <h5><xsl:value-of select="headerText"/></h5>
                  </xsl:when>
                  <xsl:otherwise>
                    <h5><xsl:value-of select="@nodeName"/></h5>
                  </xsl:otherwise>
                </xsl:choose>
                <span class="white radius label">Tilføjet d. <xsl:value-of select="umbraco.library:FormatDateTime(@updateDate, 'd')"/> af <xsl:value-of select="@writerName"/></span>
                <xsl:value-of select="umbraco.library:TruncateString(bodyText,256,'...Læs mere...')" disable-output-escaping="yes"/>
              </a>
              <hr />
            </li>
          </xsl:if>
        </xsl:for-each>
      </ul>
    </div>

    </xsl:template>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 27, 2012 @ 10:09
    Chriztian Steinmeier
    1

    Hi Frederik,

    Try to check the View Source output - it sounds like you're viewing the Web Inspector / Firebug output. 

    If the generated HTML is OK (as in what you were expecting) it's not an XSLT problem.

    It *could* be related to the fact that you're truncating the bodyText property - that one contains HTML tags, right? Shouldn't you be stripping them first? Otherwise you could easily be outputting the start tag for something but have the end tag stripped, which would ruin the layout of the rest of the page...

    /Chriztian 

  • Frederik T 242 posts 373 karma points
    Apr 27, 2012 @ 10:23
    Frederik T
    0

    Thank you for your reply.

    I am watching it with firebug, and you are correct, firefox displays the code differently when seeing page source. Though it mentions it violates nesting rules. And even so, if i highlight just one part of the text shouldnt everything be highlighted since its all inside the link tag?

    And of course! Stripping the html, i knew it seemed wrong to have it all the way out in the list view. God i feel so stupid for not realizing stuff like this before. Well thats what happens when you code alone :p

    Well all is well and good now, now everything looks just right.

    Thank you again, i hope i start to realize stuff like this by myself soon, i have been making way too many posts like this haha.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Apr 27, 2012 @ 10:41
    Chriztian Steinmeier
    0

    No worries, Frederik - it's how we all learned to walk, talk, code and make pancakes :-)

    I'd like to mention that if you're using an HTML5 doctype, the browser should allow wrapping a link around paragraphs etc. (which was not allowed in HTML4 and prvious)

    /Chriztian

  • Frederik T 242 posts 373 karma points
    Apr 27, 2012 @ 10:45
    Frederik T
    0

    I am indeed using html5 doctype (validated and all), so maybe the "view page source" in firefox doesnt recognize it? Funny, considering the broweser itself displays html5 just fine.

    But it's nice to know should i ever come across something like this again :)

Please Sign in or register to post replies

Write your reply to:

Draft