Previous and next links to move through same level nodes with sorting
Hi everyone,
I am using code from another thread to have previous/next links to move through same level nodes but am trying to move it into templates to apply sorting. Is there a way to apply sorting to this or am I doing this the wrong way? Here's the code:
That makes more sense (ancestor-or-self::) - also, you've applied the [1] predicate necessary to get only the immediate sibling. Was gonna say that :-)
The preceding- and following-sibling:: axes always work in document order, so won't work with sorting, unless you create a new sorted node set, and apply templates to that set instead.
I did wonder why the [1] was there. On a plus note, document order can be sorted by creation date in umbraco via right click on the tree so no need to sort by createDate in the xslt :)) happy times!
I was gonna say I actually wanted to build something a bit more complex but I'm still a bit lame at xslt. I have 4 pages so I wanted:
Page 1) 1 2 3 4 Next
Page 2) Previous 1 2 3 4 Next
Page3) Previous 1 2 3 4 Next
Page4) Previous 1 2 3 4
...with the bold menu items being <li class ="selected">. But somehow I think that's a bit too much after reading paging examples with queries and stuff. I will stick at it though! Thanks again :)
This should be pretty straight fwd, as long as the pages
are different nodes and not a queried page set ie 10 items of single
list split across 4 pages (though thats possible it's just more maths
based than the sepearte nodes approach as follows).
Note: Just wrote it for you now (un-tested)... You can pass a rootId by macro parameter if you want or defaults to parent of currentPage...
<!-- The fun starts here --> <!-- Input the root you want here --> <xsl:variable name="rootId"> <xsl:choose> <xsl:when test="/macro/rootId!=''"> <xsl:value-of select="/macro/rootId"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$currentPage/parent::*[@isDoc]/@id"/> </xsl:otherwise> </xsl:choose> </xsl:variable>
Thanks, the nodes are different pages yes, not 10 per page or anything. No luck with the above though, I have picked the root via macro and no list shows on my page, no error parsing, just no list at all. The xslt saves without error too.
The nodes are the same (and unique) doctype called 'PortfolioItem', could that help in making this list?
<xsl:iftest="position()=1 and $currentPage!=current()">
As you mentioned, does the top one mean current item in loop and the bottom one current item in relation to $currentPage? I've never seen the !=. before.
Previous and next links to move through same level nodes with sorting
Hi everyone,
I am using code from another thread to have previous/next links to move through same level nodes but am trying to move it into templates to apply sorting. Is there a way to apply sorting to this or am I doing this the wrong way? Here's the code:
The sorting seems wrong because how can you sort a previous and next link? Perhaps the sorting needs to be applied to the <li> itself.
Any ideas? Thanks :)
Sam.
This works perfect but without the sorting:
Not sure what was going wrong in the original post? 'Descendant' should actually say 'ancestor' in my first example.
Sam.
Hi Sam,
That makes more sense (ancestor-or-self::) - also, you've applied the [1] predicate necessary to get only the immediate sibling. Was gonna say that :-)
The preceding- and following-sibling:: axes always work in document order, so won't work with sorting, unless you create a new sorted node set, and apply templates to that set instead.
/Chriztian
Thanks Chriztian,
I did wonder why the [1] was there. On a plus note, document order can be sorted by creation date in umbraco via right click on the tree so no need to sort by createDate in the xslt :)) happy times!
I was gonna say I actually wanted to build something a bit more complex but I'm still a bit lame at xslt. I have 4 pages so I wanted:
Page 1) 1 2 3 4 Next
Page 2) Previous 1 2 3 4 Next
Page3) Previous 1 2 3 4 Next
Page4) Previous 1 2 3 4
...with the bold menu items being <li class ="selected">. But somehow I think that's a bit too much after reading paging examples with queries and stuff. I will stick at it though! Thanks again :)
Sam.
Hi Sam
This should be pretty straight fwd, as long as the pages are different nodes and not a queried page set ie 10 items of single list split across 4 pages (though thats possible it's just more maths based than the sepearte nodes approach as follows).
Note: Just wrote it for you now (un-tested)... You can pass a rootId by macro parameter if you want or defaults to parent of currentPage...
Cheers
Josh
Hi Josh,
Thanks, the nodes are different pages yes, not 10 per page or anything. No luck with the above though, I have picked the root via macro and no list shows on my page, no error parsing, just no list at all. The xslt saves without error too.
The nodes are the same (and unique) doctype called 'PortfolioItem', could that help in making this list?
Sam.
Oh, will test n edit...
Sorry Sam- was going a bit fast for my own good ;)
The preceding and following siblngs should be relative to the $currentPage not the current item in loop...
So complete working (tested) code is:
Cheers
Josh
Thanks Josh,
That's great :)) What I'm using at the moment is this so you end up with:
Previous | Back to portfolio | Next
Regarding the following lines:
<xsl:if test="position()=1 and $currentPage!=.">
and
As you mentioned, does the top one mean current item in loop and the bottom one current item in relation to $currentPage? I've never seen the !=. before.
Thanks.
Sam.
Oh they actually mean the same thing, one is just easier to type (.) and the other is easier to see.
Inside a for-each these are the same: . and current() - it is the current item in loop.
The line I changed (and was referring too) is this:
It looks like you are all sorted (without paging), hope I helped, mark it solution if it did ;)
Thanks
J
Thanks Josh, that's a great help, I'm learning all the time :)
Sam.
is working on a reply...