Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 12, 2011 @ 00:26
    Bjarne Fyrstenborg
    0

    Starterkit xslt navigation

    Hi..

    I have modified the xslt file for navigation a bit, so the paging is more appropriate and starts with 1 instead of 0.. so ?page=1, ?page=2 .. etc... 

    I have done this before on this site: http://oldengaard.dk/da/nyheder.aspx in another navigation, but the paging technique is the same ( I mean I previously was modifying the code in relation to this file http://our.umbraco.org/projects/developer-tools/paging-xslt )... however I have a problem with the first page item ... when I change umbraco.library:RequestQueryString('page') <= 0 to a value of zero the first item is is highlighted (have the currentpageitem class.. but not when I don't have the ?page=X in the url like this http://sub.ak-security.dk/da/aktuelt/nyheder.aspx

    My full xslt look like this:

    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

    <xsl:param name="currentPage"/>
    <xsl:variable name="Navigation.fromLevel">
      <xsl:choose>
        <xsl:when test="string(/macro/useSelfAsRoot) = '1'">
          <xsl:value-of select="number($currentPage/@level) + 1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:choose>
            <xsl:when test="/macro/fromLevel != ''">
              <xsl:value-of select="/macro/fromLevel" />
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="2" />
            </xsl:otherwise>
          </xsl:choose>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="Navigation.toLevel">
      <xsl:choose>
        <xsl:when test="/macro/numberOfLevels != ''">
          <xsl:value-of select="number($Navigation.fromLevel) + number(/macro/numberOfLevels) - 1" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="1000" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
        
    <xsl:variable name="Navigation.showOnlyCurrentPath">
      <xsl:choose>
        <xsl:when test="/macro/showOnlyCurrentPath != ''">
          <xsl:value-of select="/macro/showOnlyCurrentPath" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
        
    <xsl:variable name="Navigation.isSitemap">
      <xsl:choose>
        <xsl:when test="/macro/isSitemap != ''">
          <xsl:value-of select="/macro/isSitemap " />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="0" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>


    <xsl:template match="/">
      
      <xsl:call-template name="MenuItems">
        <xsl:with-param name="menuItems" select="$currentPage/ancestor-or-self::* [@level=number($Navigation.fromLevel - 1)]/* [@isDoc and name() != 'Nyhed' and name() != 'SlideArea' and ( ( $Navigation.isSitemap != '1' and string(./umbracoNaviHide) = '0' ) or ( $Navigation.isSitemap = '1' and string(./umbracoSitemapHide) = '0' ) )]"></xsl:with-param>
        <xsl:with-param name="currentLevel" select="$Navigation.fromLevel"></xsl:with-param>
        <xsl:with-param name="levelCounter" select="1"></xsl:with-param>
      </xsl:call-template>

    </xsl:template>
        
    <xsl:template name="MenuItems">
      <xsl:param name="menuItems"/>
      <xsl:param name="currentLevel"/>
      <xsl:param name="levelCounter"/>
      
      <xsl:variable name="count" select="count($menuItems)"/>
      
      <xsl:if test="$count &gt; 0">
        <ul>
          <xsl:if test="$levelCounter = 1 and /macro/navigationId">
            <xsl:attribute name="id"><xsl:value-of select="/macro/navigationId"/></xsl:attribute>
          </xsl:if>
          <xsl:attribute name="class"><xsl:value-of select="concat('lvl', $levelCounter)"/></xsl:attribute>
          
          <xsl:for-each select="$menuItems">
            <xsl:sort select="@sortOrder" order="ascending" data-type="number"/>
            
            <xsl:if test="umbraco.library:IsProtected(@id, @path) = 0 or (umbraco.library:IsProtected(@id, @path) = 1 and umbraco.library:IsLoggedOn() = 1)">
              
              <xsl:variable name="childMenuItems" select="./* [@isDoc and name() != 'Nyhed' and name() != 'SlideArea' and ( ( $Navigation.isSitemap != '1' and string(./umbracoNaviHide) = '0' ) or ( $Navigation.isSitemap = '1' and string(./umbracoSitemapHide) = '0' ) )]"/>
              <xsl:variable name="inpath" select="$currentPage/ancestor-or-self::* [@isDoc]/@id=@id"/>
              <xsl:variable name="firstitem" select="position() = 1"/>
              <xsl:variable name="lastitem" select="position() = $count"/>
              <xsl:variable name="hasChildren" select="count($childMenuItems) &gt; 0"/>

              <xsl:variable name="className">
                <xsl:if test="$inpath = '1' or $firstitem = '1' or $lastitem = '1' or $hasChildren = '1'">
                  <xsl:if test="$inpath = '1'">inpath</xsl:if>
                  <xsl:if test="$inpath = '1' and ($firstitem = '1' or $lastitem = '1')"><xsl:text</xsl:text></xsl:if>
                  <xsl:if test="$firstitem = '1'">firstitem</xsl:if>
                  <xsl:if test="$firstitem = '1' and $lastitem = '1'"><xsl:text</xsl:text></xsl:if>
                  <xsl:if test="$lastitem = '1'">lastitem</xsl:if>
                  <xsl:if test="($inpath = '1' or $firstitem = '1' or $lastitem = '1') and $hasChildren = '1'"><xsl:text</xsl:text></xsl:if>
                  <xsl:if test="$hasChildren = '1'"><xsl:text>hasChildren</xsl:text></xsl:if>
                </xsl:if>
              </xsl:variable>
              
              <li>
                <xsl:if test="$className != ''"><xsl:attribute name="class"><xsl:value-of select="$className" /></xsl:attribute></xsl:if>
                
                <a>
                  <xsl:if test="$className != ''"><xsl:attribute name="class"><xsl:value-of select="$className" /></xsl:attribute></xsl:if>
                  <xsl:attribute name="href">
                    <xsl:choose>
                      <xsl:when test="local-name() != 'ExternalLink'">
                        <xsl:value-of select="umbraco.library:NiceUrl(@id)" />
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:value-of select="./externalURL" />
                      </xsl:otherwise>
                    </xsl:choose>
                  </xsl:attribute>
                  
                  <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
                  
                  <span><xsl:value-of select="@nodeName" /></span>
                </a>

                <xsl:if test=" number($currentLevel) &lt; number($Navigation.toLevel) and ( ( $inpath = '1' and string($Navigation.showOnlyCurrentPath) != '0' ) or string($Navigation.showOnlyCurrentPath) = '0' )">
                  <xsl:call-template name="MenuItems">
                    <xsl:with-param name="menuItems" select="$childMenuItems"></xsl:with-param>
                    <xsl:with-param name="currentLevel" select="$currentLevel+1"></xsl:with-param>
                    <xsl:with-param name="levelCounter" select="$levelCounter+1"></xsl:with-param>
                  </xsl:call-template>
                </xsl:if>
              </li>
            </xsl:if>
          </xsl:for-each>
          
        </ul>
      </xsl:if>
      
    </xsl:template>

    </xsl:stylesheet>

    best regards..
    Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 12, 2011 @ 00:34
    Bjarne Fyrstenborg
    0
    <?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" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


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

      <!--
        WHAT IS THIS FILE?
        A list of news nodes written as an ul li list.
        Will have an array of classes to help styling.
        Settings include:
        - newsListPage (Will show news from this specific page)
        - newsHeadingNumber (Can be any number which will be appended to a h. Default is a h2.)
        - staticNumberOfNews (Will allways show only this number of news. No paging will be applied)
        - newsPerPage (Paging will use this to show a specific number of news per page)
    -->

      <xsl:param name="currentPage"/>
        
      <xsl:variable name="newsNode" select="umbraco.library:GetXmlNodeById(/macro/newsListPage)" />

      <xsl:variable name="allNews" select="umbraco.library:GetXmlNodeById(/macro/newsListPage)/News | $currentPage/News" />
      <xsl:variable name="news" select="$allNews [umbraco.library:DateGreaterThanOrEqual(Exslt.ExsltDatesAndTimes:datetime(),umbDate)]" />
      <xsl:variable name="newsHeadingNumber">
        <xsl:choose>
          <xsl:when test="/macro/newsHeadingNumber != ''">
            <xsl:value-of select="/macro/newsHeadingNumber" />
          </xsl:when>
          <xsl:otherwise>2</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name="numberOfNews" select="count($news)" />
      <xsl:variable name="staticNumberOfNews">
        <xsl:choose>
          <xsl:when test="/macro/staticNumberOfNews!= ''">
            <xsl:value-of select="/macro/staticNumberOfNews"/>
          </xsl:when>
          <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name="newsPerPage">
        <xsl:choose>
          <xsl:when test="/macro/newsPerPage != '' and /macro/newsPerPage != '0' and $staticNumberOfNews = '0'">
            <xsl:value-of select="/macro/newsPerPage"/>
          </xsl:when>
          <xsl:when test="$staticNumberOfNews != '0'">
            <xsl:value-of select="$staticNumberOfNews"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$numberOfNews" />
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:variable name="querystringPageNumber" select="umbraco.library:RequestQueryString('page')" />
      <xsl:variable name="pageNumber">
        <xsl:choose>
          <xsl:when test="$querystringPageNumber &lt;= 1 or string($querystringPageNumber) = '' or string($querystringPageNumber) = 'NaN'">
            1
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$querystringPageNumber"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:variable name="numberOfPages" select="$numberOfNews div $pageNumber" />

      <xsl:variable name="count">
        <xsl:choose>
          <xsl:when test="$staticNumberOfNews != ''">
            <xsl:choose>
              <xsl:when test="$staticNumberOfNews &lt; $numberOfNews">
                <xsl:value-of select="$staticNumberOfNews"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$numberOfNews"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
            <xsl:choose>
              <xsl:when test="$newsPerPage &lt; $numberOfNews">
                <xsl:choose>
                  <xsl:when test="$numberOfPages = $pageNumber">
                    <xsl:value-of select="(($newsPerPage * $pageNumber) - $numberOfNews) - $newsPerPage"/>
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="$newsPerPage"/>
                  </xsl:otherwise>
                </xsl:choose>
                <xsl:value-of select="$newsPerPage"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="$numberOfNews"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>

      <xsl:template match="/">

        <xsl:choose>
          <xsl:when test="$news != ''">

            <ul class="newsList">
              <xsl:apply-templates select="$news">
                <!--<xsl:sort select="umbDate" order="descending"/>-->
                <xsl:sort select="@sortOrder" order="descending"/>
              </xsl:apply-templates>
              <xsl:if test="$newsNode = '1235'">
                <href="{umbraco.library:NiceUrl($allNews/@id)}" class="small_button floatRight"><span>Se flere nyheder</span></a>
              </xsl:if
            </ul>
            <xsl:if test="$numberOfNews &gt; $newsPerPage and $staticNumberOfNews = '0'">
              <div class="paging">
                <xsl:if test="$pageNumber &gt; 1">
                  <href="?page={$pageNumber - 1}" class="previous">&lt;&lt;</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 name="count" select="ceiling(count($news) div $newsPerPage)" />
                </xsl:call-template>

                <xsl:choose>
                  <xsl:when test="(($pageNumber) * $newsPerPage) &lt; ($numberOfNews)">
                    <href="?page={$pageNumber + 1}" class="next">&gt;&gt;</a>
                  </xsl:when>
                  <xsl:otherwise>
                    <!--<img src="/css/gfx/x.gif" class="next" />-->
                  </xsl:otherwise>
                </xsl:choose>

              </div>

            </xsl:if>
          </xsl:when>
          <xsl:otherwise>
            <!--<xsl:element name="{concat('H', $newsHeadingNumber)}">-->
              <class="noNews"><xsl:value-of select="umbraco.library:GetDictionaryItem('News-NoNewsFound')"/></p>
            <!--</xsl:element>-->
          </xsl:otherwise>
        </xsl:choose>
      </xsl:template>


      <xsl:template match="News">
        <xsl:if test="position() &gt; $newsPerPage * number($pageNumber - 1) and position() &lt;= number($newsPerPage * number($pageNumber - 1) + $newsPerPage )">
          <xsl:variable name="active" select="$currentPage [@isDoc]/@id=@id"/>
          <xsl:variable name="inpath" select="$currentPage/ancestor-or-self::* [@isDoc]/@id=@id"/>
          <xsl:variable name="firstitem" select="position() = 1"/>
          <xsl:variable name="lastitem" select="position() = $count"/>
          <xsl:variable name="className">
            <xsl:text>news</xsl:text>
            <xsl:value-of select="concat(' pos', position())"/>
            <xsl:if test="$active = '1'"active</xsl:if>
            <xsl:if test="$inpath = '1'"inpath</xsl:if>
            <xsl:if test="$firstitem = '1'"firstitem</xsl:if>
            <xsl:if test="$lastitem = '1'"lastitem</xsl:if>
          </xsl:variable>

          <li class="{$className}">
            <div class="news_content">
            <div class="news_date">
              <span class="month"><xsl:value-of select="umbraco.library:FormatDateTime(umbDate, 'MMM')"/></span>
              <span class="day"><xsl:value-of select="umbraco.library:Replace(umbraco.library:FormatDateTime(umbDate, ' d'), ' ','')"/></span>
              <span class="year"><xsl:value-of select="umbraco.library:FormatDateTime(umbDate, 'yyyy')"/></span>
            </div>
            <div class="news_desc">
            <xsl:element name="{concat('H', $newsHeadingNumber)}">
              <xsl:attribute name="class">
                <xsl:text>newsHeading</xsl:text>
              </xsl:attribute>
              <href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="umbHeadline"/>
              </a>
            </xsl:element>
            <!--<div class="newsDate">
              <xsl:value-of select="umbraco.library:FormatDateTime(umbDate, umbraco.library:GetDictionaryItem('gDateFormat'))"/>
            </div>-->
            <div class="newsSplit"></div>
            <class="newsSummary">
              <xsl:value-of select="newsSummary" disable-output-escaping="yes"/>
            </p>
            <p><title="{current()/@nodeName}" href="{umbraco.library:NiceUrl(current()/@id)}" class="read_more">Læs mere &#187;</a></p>
            </div>
            </div>
          </li>
        </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">
            <class="pageitem" href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i}">
              <xsl:value-of select="$i" />
            </a>
          </xsl:if>
          <xsl:if test="$page = $i">
            <span class="currentpageitem">
              <xsl:value-of select="$i" />
            </span>
          </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>
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 12, 2011 @ 00:36
    Bjarne Fyrstenborg
    0

    Just ignore the first xslt code, as it was missing some of the code.. and somehow I couldn't just change it..

    Bjarne

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 12, 2011 @ 14:19
    Rune Grønkjær
    2

    Hi Bjarne,

    Yeah, I have been meaning to fix that for some time, and did it on my last project. Your post have been a good excuse to get it implemented in the Starter Kit and it will be released next time. Until then here's the links to the new files you need for properly paging of the news list.

    http://www.teacommerce.dk/blogMedia/general_newsList.xslt
    http://www.teacommerce.dk/blogMedia/utils_paging.xslt

    The first one is the newslist which you can owerwrite. The second one is the new paging, which I have moved to it's own xslt for reuse. It can page anything.

    Just throw them both in the xslt folder and your'e good to go.

    /Rune 

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 12, 2011 @ 16:40
    Bjarne Fyrstenborg
    0

    Hi Rune

    Thanks for the files.. just what I was looking for..
    It works perfect.. and nice the paging has it's own file, so the code is reused when having other files using the paging too..

    Bjarne

  • Rune Grønkjær 1372 posts 3103 karma points
    Nov 12, 2011 @ 19:04
    Rune Grønkjær
    0

    Sorry Bjarne, I made a greedy replace in the newslist xslt. I have corrected the error and you can download a new one from the link above.

    Some classes and xml property names where all wrong.

    /Rune

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Nov 12, 2011 @ 19:46
    Bjarne Fyrstenborg
    0

    Hi Rune..

    Yes, I've noticed that you use items instead of news some places, but it doesn't matter.. of course the classes must be the same as the ones in css, but the names of the varibles could be items as well...

    I see you have changed one of the first lines from:
    <xsl:variable name="allItems" select="umbraco.library:GetXmlNodeById(/macro/newsListPage)/Items | $currentPage/News" />

    to:
    <xsl:variable name="allItems" select="umbraco.library:GetXmlNodeById(/macro/newsListPage)/News | $currentPage/News" />

    Furthermore I added a couple of classes to the current page and page item:
    <xsl:choose>
          <xsl:when test="number($pageNumber) = number($i)">
            
            <span class="currentpageitem">
              <xsl:value-of select="$i" />
            span>
          </xsl:when>
          <xsl:otherwise>
            
            <class="pageitem" href="?page={$i}{$extraParams}">
              <xsl:value-of select="$i" />
            </a>
          </xsl:otherwise>
    </xsl:choose>

    But without the changes you just made it seem to work just fine here: http://sub.ak-security.dk/da/aktuelt/nyheder.aspx , but only on currentPage.. with the correction I first wrote, it also works on frontpage..

    Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft