Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Nov 12, 2010 @ 07:25
    syn-rg
    0

    Next page link?

    I'm trying to create a "Next page" link.

    So far I'm using the Content Picker to select the next page, but as I'm bound to have over a hundred pages this seems silly. Here's the code I'm using for this doomed idea:

    <?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:template match="/">
            
            <!-- some output -->
            
            <!-- output link here, if there was a node picked: -->
            <xsl:apply-templates select="$currentPage/nextPageLink[normalize-space()]" />
            
            <!-- some more output -->
            
    </xsl:template>

    <!-- Template for link -->
    <xsl:template match="nextPageLink">
            <a href="{umbraco.library:NiceUrl(.)}"><xsl:value-of select="@nodeName"/></a>
    </xsl:template>




    </xsl:stylesheet>

    Is there anyway I can have a "Next page" link appear on each page as it appears in the Content tree?

    So a Parent (level 1) node would go to a child (2), then the child to a grand child (3). But the grand child could then go to the next page even if it's a (level 1).

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Nov 12, 2010 @ 08:10
    Sebastiaan Janssen
    0

    You should be able to do this with $currentPage::following-node[1] ([1] being the first node in the set of following nodes). Have a look at this excellent axes vizualizer for a look at how that selects nodes.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 12, 2010 @ 08:16
    Dirk De Grave
    0

    JV,

    You'll have to write some code to find the next page using the xpath axis. More info on this can be found on this wiki page. I guess you need to find out whether the current page has a child node and use that if it exists. If not, use the following sibling axis to find a node at the same level, and if that doesn't exist, use the following axis to get to the next page on a higher level.

    Hope this helps.

    Regards,

    /Dirk

  • syn-rg 282 posts 425 karma points
    Nov 15, 2010 @ 00:36
    syn-rg
    0

    Thanks Sebastiaan and Dirk,

    I've created this so far, but it's not displaying in the front end.

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


    <xsl:if test="count($currentPage/following::node) != 0">
    next
    <a href="{umbraco.library:NiceUrl($currentPage/following::node[1]/@id)}">
    <xsl:value-of select="$currentPage/following::* [@isDoc][1]/@nodeName"/>
    </a>
    </xsl:if>


    </xsl:template>

    </xsl:stylesheet>
  • syn-rg 282 posts 425 karma points
    Nov 18, 2010 @ 05:15
    syn-rg
    0

    This is getting closer, but still not what I'm after.

    It's not linking to pages on the same level.

    <?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:template match="/">
      
      <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1' and name() != 'HomeImage' and name() != 'projectImage']">
        <div id="next_section">
          <p>Next page:&nbsp;<a href="{umbraco.library:NiceUrl($currentPage/descendant::*/@id)}" title="{$currentPage/descendant::*/@nodeName}">
            <xsl:value-of select="$currentPage/descendant::*/@nodeName"/>
            </a>
          </p>
        </div>
      </xsl:for-each>

      
      
    </xsl:template>

    </xsl:stylesheet>
  • Michael Falch Madsen 70 posts 92 karma points
    Nov 18, 2010 @ 15:05
    Michael Falch Madsen
    0

    Maybe you can find some help here

    PrevNext Links

     

  • syn-rg 282 posts 425 karma points
    Nov 29, 2010 @ 00:23
    syn-rg
    0

    Almost there, just need the link to display correctly with the NiceUrl. Currently it's giving me the /home/office.aspx link text.

    Anyone able to help me get this over the line?

    <?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="myLevel" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2 and string(umbracoNaviHide) != '1']"/>
    <xsl:variable name="nextId1" select="number($myLevel/following-sibling::* [@isDoc][1]/@id)"/>

    <xsl:variable name="nextId">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*/@id" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*/@id" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:if test="$nextId &gt; 0">
        <div id="next_section">
          <p>Next page:
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
              </xsl:attribute>
              <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
            </a>
          </p>
        </div>
      </xsl:if>
      
    </xsl:template>   
              
    </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 29, 2010 @ 01:08
    Kim Andersen
    0

    Do you want to show the node name of the next node instead of the URL? If so, with your current code, you could create a new variable like this:

    <xsl:variable name="nextName">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*/@nodeName" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*/@nodeName" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    And then use this variable as the link text by replacing this:

    <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>

    With this:

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

    Was that what you wanted to achieve?

    /Kim A

  • syn-rg 282 posts 425 karma points
    Nov 29, 2010 @ 02:00
    syn-rg
    0

    Hi Kim,

    I tried your suggestion. The name of the next node is displayed, but the link is incorrect.

    Instead of linking to www.website/home/office.aspx, it's linking to www.website/office.aspx

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 29, 2010 @ 10:29
    Kim Andersen
    0

    How does your structure look in the content section? I'm guessing that your /home.aspx is on level 1 and the office.aspx is on level 2.

    /Kim A

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 29, 2010 @ 14:10
    Kim Andersen
    0

    Hmm... I can see that my whole answer didn't get saved in my last post. What I was trying to say was, that if your content is build the way i said before (home.aspx on level 1 and office.aspx on level 2), you can choose if the first level shall be vissible in the URLs or not.

    Find this line in the web.config (around line 24):

    <add key="umbracoHideTopLevelNodeFromPath" value="true" />

    If you change this value to false, then your top most node (the home-node in your solution) will be a part of the URL. As default the option is set to true.

    /Kim A

  • syn-rg 282 posts 425 karma points
    Nov 29, 2010 @ 23:39
    syn-rg
    0

    Hi Kim,

    My content structure looks like this:

    Content
    --Site
    ----Home
    --------Office
    --------Retail
    --------Hotels
    --------Education
    --------Government
    ----About Us
    --------Our story
    ----Contact

    When I tried to add your nextName code the name of the node on the front end displayed correctly but the link didn't work as it was missing the parent node in the link.

    I tried it again changing the following:

    <add key="umbracoHideTopLevelNodeFromPath" value="false" />

    But this didn't help either, instead of linking to www.website/site/home/office.aspx, it's linking to www.website/site/office.aspx

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 30, 2010 @ 00:53
    Kim Andersen
    0

    Hmm... That is pretty strange. I actually thought that you said the links where fine, but you just needed to write the correct link text. Besides that I think that you should stick with the true value in the umbracoHideTopLevelNodeFromPath key. I only wrote it because I thought you had another structure :)

    If you've got the right id of the node where you are also getting the name from, I can't understand why the link won't work. Are the page vissible if you go to the generated link or do you get a 404? Or have you changed the URL of that page somehow (eg. through the umbracoUrlName, URL rewriting or something like that)? And one last thing, does the wrong link only fail on the office.aspx-node or is the generated link wrong on all of the nodes?

    /Kim A

  • syn-rg 282 posts 425 karma points
    Nov 30, 2010 @ 05:27
    syn-rg
    0

    Hi Kim,

    The link works it's just the displayed name in the front end. Currenlty it's displaying like this:

    Next page: /home/office.aspx

    It should display like this:

    Next page: Office

  • Rich Green 2246 posts 4008 karma points
    Nov 30, 2010 @ 09:30
    Rich Green
    0

    Hey JV,

    That's because you are displaying the results of niceURL as your link and your href.

    Change

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

    to

    <!-- start writing XSLT -->
      <xsl:if test="$nextId &gt; 0">
        <div id="next_section">
          <p>Next page:
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
              </xsl:attribute>
              <xsl:value-of select="$currentPage/@nodeName"/>
            </a>
          </p>
        </div>
      </xsl:if>

    Rich

  • Kim Andersen 1447 posts 2196 karma points MVP
    Nov 30, 2010 @ 13:40
    Kim Andersen
    2

    Hmm... wasn't that what I told you how to acomplish in my answer right here?

    To create a new variable called nextName like this:

    <xsl:variable name="nextName">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*/@nodeName" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*/@nodeName" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    and then change the code to this:

    <xsl:if test="$nextId &gt; 0">
        <div id="next_section">
          <p>Next page:
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
              </xsl:attribute>
              <xsl:value-of select="$nextName"/>
            </a>
          </p>
        </div>
      </xsl:if>

    @Rich: The solution you provided would just use the name of the current page as the link text, and I don't think that is what we're trying to achieve - Or are we? :S

    /Kim A

     

  • Rich Green 2246 posts 4008 karma points
    Nov 30, 2010 @ 14:11
    Rich Green
    0

    Hey Kim,

    You're right, my bad for not reading the whole thread ;) 

    Rich

     

     

  • syn-rg 282 posts 425 karma points
    Nov 30, 2010 @ 23:30
    syn-rg
    0

    Thanks Kim,

    You're original post was right! But I was replacing both "umbraco.library:NiceUrl($nextId)" with "$nextName". Which was my mistake.

    Thanks for your persistance with this problem, and thanks to Rich Green for your efforts.

    For those out there who want a link to the next page in their node structure, here's the final 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" 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="myLevel" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2 and string(umbracoNaviHide) != '1']"/>
    <xsl:variable name="nextId1" select="number($myLevel/following-sibling::* [@isDoc][1]/@id)"/>

    <xsl:variable name="nextId">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*/@id" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*/@id" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
        
    <xsl:variable name="nextName">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*/@nodeName" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*/@nodeName" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    <xsl:template match="/">

    <!-- start writing XSLT -->
      <xsl:if test="$nextId &gt; 0">
        <div id="next_section">
          <p>Next page:
            <a>
              <xsl:attribute name="href">
                <xsl:value-of select="umbraco.library:NiceUrl($nextId)"/>
              </xsl:attribute>
              <xsl:value-of select="$nextName"/>
            </a>
          </p>
        </div>
      </xsl:if>

      
    </xsl:template>   
              
    </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 00:12
    Kim Andersen
    0

    Ahh great news JV!

    I'm glad you got it working. Now I understand why there was suddenly a problem with the link instead of the link text :)

    /Kim A

  • syn-rg 282 posts 425 karma points
    Dec 01, 2010 @ 00:41
    syn-rg
    0

    Thanks Kim,

    I did just have a thought. I have some doctypes in my content tree that I don't want to show up in the "Next page" link.

    I could use umbracoNaviHide on these items, however this hides the entire macro from the page.

    Ideally I'm trying to find a way to hide certain doctypes and have the "Next page" skip to the next doctype.

    e.g.
    About Us
    ----Image node
    Contact Us

    The idea would be to hide "Image node" from the "Next page" link and the "About Us" "Next page" link display the "Contact Us" page.

    Does that make sense?

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 01, 2010 @ 13:25
    Kim Andersen
    1

    If you want to exclude nodes with a special document type I'm pretty sure you can just throw those nodes away by changing your variables to something like this:

    <xsl:variable name="nextId">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*[name()!='YourDocTypeAliasHere']/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*[name()!='YourDocTypeAliasHere']/@id" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*[name()!='YourDocTypeAliasHere']/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*[name()!='YourDocTypeAliasHere']/@id" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>
       
    <xsl:variable name="nextName">
      <xsl:choose>
        <xsl:when test="count($currentPage/descendant::*[name()!='YourDocTypeAliasHere']/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/descendant::*[name()!='YourDocTypeAliasHere']/@nodeName" />
        </xsl:when>
        <xsl:when test="count($currentPage/following::*[name()!='YourDocTypeAliasHere']/@nodeName) &gt; 0">
            <xsl:value-of select="$currentPage/following::*[name()!='YourDocTypeAliasHere']/@nodeName" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    Haven't tested it though, but it makes sense in my head :)

    /Kim A

  • syn-rg 282 posts 425 karma points
    Dec 01, 2010 @ 23:48
    syn-rg
    0

    Works like a cham!

    Thanks again Kim, you're a legend!

    Cheers,
    JV

  • Kim Andersen 1447 posts 2196 karma points MVP
    Dec 04, 2010 @ 17:02
    Kim Andersen
    0

    No problem JV. Just glad I'm able to help out :)

    /Kim A

Please Sign in or register to post replies

Write your reply to:

Draft