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..
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>
It works when im on Page 1 and Page 3 but gives error on Page 2?
You might try using the @level attribute.
da is level 1, so Page1, Page2, Page3 are all level 2
You'll also want to wrap your a tags in an if test (sometimes the previd and nextid won't exist).
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..
yep.. it's working now.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<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 > 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 > 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>
You were right Sean. Added a test to see if i'm at the start or end of the tree and i works! Thanks!
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
Thanks to you both, this was what I was looking for too for moving between gallery items :)
Sam.
is working on a reply...