Copied to clipboard

Flag this post as spam?

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


  • Brian 77 posts 251 karma points
    Jan 08, 2015 @ 15:13
    Brian
    0

    Incorrect number in list and missing nodes

    Hi guys,

    Working on a list where the first item/node in the list is missing (by design).  This bit is working fine but there are only 4 items on each page and the last item/node is missing... Any ideas why?

    Here is the code:

     

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#x00A0;">]>

    <xsl:stylesheet  version="1.0"

      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

      xmlns:msxml="urn:schemas-microsoft-com:xslt"

      xmlns:umbraco.library="urn:umbraco.library"

      exclude-result-prefixes="msxml umbraco.library">

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

     

      <xsl:param name="currentPage"/>

    <xsl:variable name="recordsPerPage" select="5"/>

        <xsl:variable name="pageNumber">

          <xsl:choose>

            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 1 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>

            <xsl:otherwise>

              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>

            </xsl:otherwise>

          </xsl:choose>

        </xsl:variable>

        <xsl:variable name="numberOfRecords" select="count($currentPage/parent::*/ReviewerSection/ReviewerBioPage/Review [@isDoc and string(./umbracoNaviHide) != '1'])"/>

     

     

      <xsl:template match="featuredImage">

    <img src="{.}"  />

    </xsl:template>

     <xsl:template match="headshot">

    <img src="{.}" alt="{./headshot}" title="{./firstName}" />

    </xsl:template>

       <xsl:template match="/">

      <xsl:variable name="excerptLength">

        <xsl:choose>

          <xsl:when test="string(/macro/excerptLength) != ''">

            <xsl:value-of select="/macro/excerptLength"/>

          </xsl:when>

          <xsl:otherwise>150</xsl:otherwise>

        </xsl:choose>

      </xsl:variable>

     

     <xsl:variable name="numberOfItems">

        <xsl:choose>

          <xsl:when test="/macro/numberOfItems != ''">

            <xsl:value-of select="/macro/numberOfItems"/>

          </xsl:when>

          <xsl:otherwise>9999</xsl:otherwise>

        </xsl:choose>

      </xsl:variable>

        <xsl:variable name="recordsPerPage" select="5"/>

     

    <ul>

          <xsl:for-each select="$currentPage/parent::*/ReviewerSection/ReviewerBioPage/Review [@isDoc and string(./umbracoNaviHide) != '1']">

    <xsl:sort select="datePosted" order="descending" />

            <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">

     

     

     

    <li>

    <figure>

    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:apply-templates select="ancestor-or-self::*[normalize-space(featuredImage)][1]/featuredImage" /></a>

    <!--<span class="wordrated">show STOPPER</span>-->

    </figure>

    <div class="revlist">

    <h3><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" disable-output-escaping="yes"/> - <span class="sml"><xsl:value-of select="typeOfProduction"/></span></a></h3>

    <figure>

     

    <xsl:apply-templates select="ancestor-or-self::*[normalize-space(headshot)][1]/headshot" /></figure>

    <h5><xsl:value-of select= "umbraco.library:FormatDateTime(datePosted, 'dd/MM/yyyy')" /> | reviewed by <b><xsl:value-of select="../firstName"/>&nbsp;<xsl:value-of select="../surname"/></b></h5>

    <p>

      <xsl:choose>

                    <xsl:when test="string($excerptLength) != '0'">

                      <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(mainReviewContent), number($excerptLength), '...')" disable-output-escaping="yes"/>

                    </xsl:when>

                    <xsl:otherwise>

                      <xsl:value-of select="mainReviewContent" disable-output-escaping="yes"/>

                    </xsl:otherwise>

                  </xsl:choose>

      </p> <a href="{umbraco.library:NiceUrl(@id)}" class="read">Read the full review</a>

     

    </div><!--revlist-->

    </li>

     

     

     

            </xsl:if>

          </xsl:for-each>

     </ul>

    <xsl:if test="$pageNumber &gt; 1">

          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/?page={$pageNumber - 1}" class="navbuttonprev">Previous Page</a>

        </xsl:if>

        <xsl:call-template name="for.loop">

          <xsl:with-param name="i">500</xsl:with-param>

          <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>

          <xsl:with-param name="count" select="ceiling(count($currentPage/*[@isDoc and string(./umbracoNaviHide) != '1']) div $recordsPerPage)"></xsl:with-param>

        </xsl:call-template>

        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">

          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/?page={$pageNumber + 1}" class="navbuttonnext">Next Page</a>

        </xsl:if>

      </xsl:template>

     

      <xsl:template name="for.loop">

        <xsl:param name="i"/>

        <xsl:param name="count"/>

        <xsl:param name="page"/>

        <xsl:if test="$i &lt;= $count">

          <xsl:if test="$page != $i">

            <a href="{umbraco.library:NiceUrl($currentPage/@id)}/?page={$i}" class="navbutton">

              <xsl:value-of select="$i" />

            </a>

          </xsl:if>

          <xsl:if test="$page = $i">

            <xsl:value-of select="$i" />

          </xsl:if>

        </xsl:if>

        <xsl:if test="$i &lt;= $count">

          <xsl:call-template name="for.loop">

            <xsl:with-param name="i">

              <xsl:value-of select="$i + 1"/>

            </xsl:with-param>

            <xsl:with-param name="count">

              <xsl:value-of select="$count"/>

            </xsl:with-param>

            <xsl:with-param name="page">

              <xsl:value-of select="$page"/>

            </xsl:with-param>

          </xsl:call-template>

        </xsl:if>

      </xsl:template>

    </xsl:stylesheet>

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 08, 2015 @ 16:21
    Jan Skovgaard
    0

    Hi Brian

    How many nodes does your $numberOfRecords variable contain?

    Try doing a and see how many nodes it returns - is it the same as you expect? Otherwise you might need to change your expression to include more nodes perhaps.

    Not saying that this is the issue, just suggesting a place to start debugging.

    Looking forward to hearing from you.

    /Jan

  • Brian 77 posts 251 karma points
    Jan 08, 2015 @ 16:55
    Brian
    0

    This one was a big fat DOH!!!  I'd unwittingly stripped out the first <li></li> in the list which is why I was always short by 1

    Going to go and lie down in a darkened room now!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 08, 2015 @ 18:31
    Jan Skovgaard
    0

    Hi Brian

    Haha, oh well...it happens to all of us. The main thing is that you figured out the issue and was able to move on :D

    Happy coding!

    /Jan

  • 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