Copied to clipboard

Flag this post as spam?

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


  • Dan 2 posts 22 karma points
    May 22, 2012 @ 17:41
    Dan
    0

    Up a Level (Link to parent Node)

    I’m very new to XSLT... as in i’ve never touched any until this morning and despite attempting something i thought should be fairly straight forward i’ve been stuck for hours.

    I want to create a link to a pages parent page.

    Unfortunately I’ve hit a problem in that while it works it will only work for one level. For example here is my site structure.

    Home

                PageA

                                    SubPage1

                                    SubPage2

     

    If I navigate to PageA and then use my “up one level” link it will deposit me on the Home page. Fabtastic!

    However should i try to use the link more than once in a row (i.e i start at SubPage1 and use the link to get back to PageA and then attempt to use the link again) it will do nothing... the link will show as pointing to the current page.

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

     

    <!-- start writing XSLT -->

    <ul>

    <li>

             <a href="{umbraco.library:GetXmlNodeById(./@parentID)/@nodeName}">

                    Up a Level

                    </a>

    </li>

    </ul>

     

    </xsl:template>

     

    </xsl:stylesheet>

    I’ve used variations in my href xslt (“..” for example)  but it all seems to have the same effect. After one “Up a Level” the href points to itself. I’m sure i’m doing something very silly somewhere and a gentle prod in the right direction would be most welcome!

    Kind Regards
    Dan Brown

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 23, 2012 @ 02:17
    Chriztian Steinmeier
    0

    Hi Dan,

    Whichever page you're on ($currentPage in Umbraco terms), this will give you a link to the parent page:

    <xsl:if test="not($currentPage/parent::root)">
       <a href="{umbraco.library:NiceUrl($currentPage/@parentID)}">Up a level</a>
    </xsl:if>

    NiceUrl() takes the ID of the node to create the link to, but we need to make sure we give it a valid ID - so the xsl:if makes sure we're not at the top of the Content tree.  

    /Chriztian

  • Dan 2 posts 22 karma points
    May 23, 2012 @ 10:11
    Dan
    0

    Thank you so much Chriztian! You have saved my fragile sanity, much appriciated! :)

Please Sign in or register to post replies

Write your reply to:

Draft