Copied to clipboard

Flag this post as spam?

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


  • Eric Warren 48 posts 68 karma points
    Jul 19, 2010 @ 22:13
    Eric Warren
    0

    Paging XSLT Item List

    I currently have The Runway Rss Feedviewer pulling in an rss feed with about 50 items.  I was wondering if there was a simple way to page the items.

  • Simon Justesen 436 posts 203 karma points
    Jul 19, 2010 @ 23:16
    Simon Justesen
    0

    Hi Eric,

    Take a look at this: http://www.nibble.be/?p=11

    /Simon

  • Eric Warren 48 posts 68 karma points
    Jul 20, 2010 @ 20:05
    Eric Warren
    0

    Yea i have tried his code but is seem very slopy and plus i get errors. Thank for the link

  • Eric Warren 48 posts 68 karma points
    Jul 20, 2010 @ 22:55
    Eric Warren
    0

    Simon,

    I found the same code in a project that someone posted on umbraco.  I have implemented the code but i get one error.  Im not sure if you could look at it and help me out.  Im lost at this point.

     

    Error occured

    Error in XSLT at line 73, char 11
    71:       <ul>
    72:       <xsl:for-each select="$feedContent//item">
    73: >>>   <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )"> <<<
    74:       <li>
    75:  

     

     

     

    <?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="excerptLength" select="1000" />

      <xsl:variable name="feed" select="string('http://thesaltminechurch.podbean.com/feed/')"/>
      <!-- cache for 30 minutes (1.800 seconds) -->
      <xsl:variable name="cacheRate" select="number(1800)"/>

      <xsl:template match="/">

        <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>

        <!-- start writing XSLT -->
        <xsl:choose>

          <xsl:when test="$feed != ''">
            <xsl:variable name="feedContent" select="umbraco.library:GetXmlDocumentByUrl($feed, number($cacheRate))"/>
            <xsl:choose>
              <xsl:when test="$feedContent != 'error'">
                <xsl:call-template name="renderFeed">
                  <xsl:with-param name="feedContent" select="$feedContent"/>
                </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                <p>
                  <strong>Feed Viewer Macro Error: Error fetching feed</strong><br />
                  The feed '<xsl:value-of select="$feed"/>' could not be loaded. Verify that the feed url exists and that you have an
                  active internet connection
                </p>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <p>
              <strong>Feed Viewer Macro Error: No feed chosen</strong><br />
              Please make sure to add a value in the "Feed Url" parameter
            </p>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>

      <xsl:template name="renderFeed">
        <xsl:param name="feedContent"/>
        <xsl:if test="count($feedContent//item) &gt; 0">

     

          <ul>
            <xsl:for-each select="$feedContent//item">
              <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber - 1) and position() &lt;= number($recordsPerPage * number($pageNumber - 1) + $recordsPerPage )">
                <li>


                  <h2>

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

                  </h2>
                  <strong>
                    <small>
                      <xsl:value-of select="umbraco.library:LongDate(pubDate)"/>
                    </small>
                  </strong>
                  <br/>
                  <br/>
                  <xsl:choose>
                    <xsl:when test="string($excerptLength) != '0'">
                      <p>
                        <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(description), number($excerptLength), '...')" disable-output-escaping="yes"/>
                      </p>
                    </xsl:when>
                    <xsl:otherwise>
                      <!-- <xsl:value-of select="description" disable-output-escaping="yes"/> -->
                    </xsl:otherwise>
                  </xsl:choose>
                  <br/>
                  <a href=" {enclosure/@url} ">
                    <img style="vertical-align:middle;" src="/images/play.jpg" />  Listen Now
                  </a>
                </li>
                <br/>
                <br/>
                <br/>
                <br/>
              </xsl:if>

            </xsl:for-each>
            <!-- <li class="last"><xsl:text disable-output-escaping="yes">&amp;</xsl:text>nbsp;</li> -->
          </ul>

        </xsl:if>
        <xsl:if test="$pageNumber &gt; 1">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber - 1}">previous</a>
        </xsl:if>
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling(count($currentPage/node) div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
        <xsl:if test="(($pageNumber) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$pageNumber + 1}">next</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)}/{$i}" >
              <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>

  • Josh Townson 67 posts 162 karma points
    Jul 21, 2010 @ 13:46
    Josh Townson
    0

    Hi Simon

    Your variables are declared inside the main template (match="/") so they are not available outside of that template. If you move the variable declarations up just a little, I think it will work fine :)

    <?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="excerptLength" select="1000" />

    <xsl:variable name="feed" select="string('http://thesaltminechurch.podbean.com/feed/')"/>
    <!-- cache for 30 minutes (1.800 seconds) -->
    <xsl:variable name="cacheRate" select="number(1800)"/>

    <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:template match="/">

    <!-- start writing XSLT -->

    and then the rest of the xslt

  • Eric Warren 48 posts 68 karma points
    Jul 21, 2010 @ 14:23
    Eric Warren
    0

    Simon, 

    thanks that fixed that one.  One more for you.  I get the following error

    System.Xml.Xsl.XslLoadException: The variable or parameter 'numberOfRecords' is either not defined or it is out of scope.

    Here is the line of code     <xsl:if test="(($pageNumber) * $recordsPerPage)  &lt; ($numberOfRecords) ">

     I don't see any where i can define the number of records. If I take out the $numberOfRecords it works and renders on the page.  The only thing is the next button thows an Page not found - No umbraco document matches the url 'http://localhost/resources/current-sermons.aspx/2'

    You have any suggestion?

  • Josh Townson 67 posts 162 karma points
    Jul 21, 2010 @ 15:43
    Josh Townson
    0

    Hi Eric,

    you need to define the variable numberOfRecords

    ...
    <xsl:template name="renderFeed">
    <xsl:param name="feedContent"/>
    <xsl:variable name="numberOfRecords" select="count($feedContent//item)"/>
    <xsl:if test="count($feedContent//item) &gt; 0">
    ...

    but there are a few other inconsistencies in the code you've got - the paging code is designed for multiple nodes underneath the current one - you need to change the for.loop template - where it is called, it is counting the number of subnodes - I think that should use the $numberOfRecords variable.

    Finally the page links need changing - in the foor.loop template change:

          <xsl:if test="$page != $i">
    <a href="{umbraco.library:NiceUrl($currentPage/@id)}/{$i}" >
    <xsl:value-of select="$i" />
    </a>
    </xsl:if>

    to

          <xsl:if test="$page != $i">
    <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i}" >
    <xsl:value-of select="$i" />
    </a>
    </xsl:if>

    I think that will cover everything :)

    /Josh

  • Eric Warren 48 posts 68 karma points
    Jul 21, 2010 @ 19:03
    Eric Warren
    0

    Josh,

    Thanks for all you help

Please Sign in or register to post replies

Write your reply to:

Draft