Copied to clipboard

Flag this post as spam?

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


  • Michael Falch Madsen 70 posts 92 karma points
    Nov 03, 2010 @ 14:08
    Michael Falch Madsen
    0

    Trying to build prev next links

    I'm having trouble building Prev Next links to my pages/nodes.

    I on a shared host running Umbraco v4.5.2 and .net4.0

    I've following structure:

    - da
    -- Page1
     --- Sub thing
     --- Sub thing
    -- Page 2
    -- Page 3

    I would like to have prev next links for the level with Page 1, Page 2...

    My code works for some pages but on others i says: Error parsing XSLT file: \xslt\PrevNext.xslt

     

    <xsl:variable name="nextId" select="number($currentPage/following-sibling::* [@isDoc][1]/@id)"/>
    <xsl:variable name="prevId" select="number($currentPage/preceding-sibling::* [@isDoc][1]/@id)"/>


    <xsl:template match="/">

    <!-- start writing XSLT -->
           
        <div id="prev">
          <a>
            <xsl:attribute name="href">
              <xsl:value-of select="umbraco.library:NiceUrl($prevId)"/>
            </xsl:attribute>
            PREV
          </a>
        </div>
        <div id="next">
          <a>
            <xsl:attribute name="href">
              <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
            </xsl:attribute>
            NEXT
          </a>
        </div>
      
    </xsl:template>

  • Michael Falch Madsen 70 posts 92 karma points
    Nov 03, 2010 @ 14:12
    Michael Falch Madsen
    0

    It works when im on Page 1 and Page 3 but gives error on Page 2?

  • Sean Mooney 131 posts 158 karma points c-trib
    Nov 03, 2010 @ 14:18
    Sean Mooney
    0

    You might try using the @level attribute.

    da is level 1, so Page1, Page2, Page3 are all level 2

    <xsl:variable name="myLevel" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2]"/>
    <xsl:variable name="nextId" select="number($myLevel/following-sibling::* [@isDoc][1]/@id)"/>
    <xsl:variable name="prevId" select="number($myLevel/preceding-sibling::* [@isDoc][1]/@id)"/>

    You'll also want to wrap your a tags in an if test (sometimes the previd and nextid won't exist).

  • Michael Falch Madsen 70 posts 92 karma points
    Nov 03, 2010 @ 14:20
    Michael Falch Madsen
    0

    The umbraco.config was'nt updated after i sorted my pages, and after the umbraco.config showed the correct order in pages it's the first and last page which is reporting error, so i think i'm just lacking a test if i'm at the start or end of my tree..

  • Michael Falch Madsen 70 posts 92 karma points
    Nov 03, 2010 @ 14:23
    Michael Falch Madsen
    0

    yep.. it's working now.

    <?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="nextId" select="number($currentPage/following-sibling::* [@isDoc][1]/@id)"/>
    <xsl:variable name="prevId" select="number($currentPage/preceding-sibling::* [@isDoc][1]/@id)"/>


    <xsl:template match="/">

    <!-- start writing XSLT -->
            
        <xsl:if test="$prevId &gt; 0">
          <div id="prev">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($prevId)"/>
              </xsl:attribute>
              PREV
            </a>
          </div>
        </xsl:if>

        <xsl:if test="$nextId &gt; 0">
          <div id="next">
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
              </xsl:attribute>
              NEXT
            </a>
          </div>
        </xsl:if>
      
    </xsl:template>   

    </xsl:stylesheet>

  • Michael Falch Madsen 70 posts 92 karma points
    Nov 03, 2010 @ 14:24
    Michael Falch Madsen
    0


    You were right Sean. Added a test to see if i'm at the start or end of the tree and i works! Thanks!

  • Sean Mooney 131 posts 158 karma points c-trib
    Nov 03, 2010 @ 14:27
    Sean Mooney
    0

    You'll want to test it on a "Sub thing" page, as I don't think it will pick up Page1, Page2, etc. Instead it would link to other "Sub thing" pages.

    If you want it to link to Page1, Page2 then you'll want to look at the @level attribute

  • Sam 184 posts 209 karma points
    Feb 05, 2011 @ 16:30
    Sam
    0

    Thanks to you both, this was what I was looking for too for moving between gallery items :)

    Sam.

Please Sign in or register to post replies

Write your reply to:

Draft