Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1199 posts 2567 karma points
    Oct 07, 2009 @ 02:28
    Amir Khan
    0

    Get Childnodes of Defined parent if you are on parent node

    I have the code below which prints the childnodes of whichever parent node i am under. Is there a way to only print something if i am under a certain node.

    Basically like "If currentNode = 1122 then print children, otherwise do nothing" I'm not that experienced with XSLT and could really use some help!

     

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

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="3"/>

    <xsl:template match="/">

    <!-- The fun starts here -->

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <ul>
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="@nodeName"/>
    </a>
    </li>
    </ul>
    </xsl:for-each>


    </xsl:template>

    </xsl:stylesheet>
  • skiltz 501 posts 701 karma points
    Oct 07, 2009 @ 02:52
    skiltz
    0

    somehting like:

     

    <xsl:if test="$currentPage/@id = 1122">
    </xsl:if>

  • Amir Khan 1199 posts 2567 karma points
    Oct 07, 2009 @ 03:01
    Amir Khan
    0

    Yes! Thank you!

  • Amir Khan 1199 posts 2567 karma points
    Oct 07, 2009 @ 03:43
    Amir Khan
    0

    That worked great. Is it possible now to define something like below, what's happening now is that when I actually end up on one of the children, it hides the navigation. I didn't even think about that when i posted my question before.

    <xsl:if test="$currentPage/@id = 1122" or child of 1122>
    </xsl:if>

     

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 07, 2009 @ 04:02
    Nik Wahlberg
    0

    he first thing that comes to mind is that you proably want to avoid hard-coding Id's in your code (XSLT or .NET). It sounds like you have a context-sensitive nav that basically just shows the children of the current parent in your master template? If that is the case, then you should look at doing the following:

    <ul>
    <xsl:for-each select="$currentPage/descendant-or-self::node [string(data [@alias='umbracoNaviHide']) != '1']">
        <li>
            <a href="{umbraco.library:NiceUrl(@id)}">
                <xsl:value-of select="@nodeName"/>
            </a>
        </li>
    </xsl:for-each>
    </ul>

    This should give you the children of the current pages parent (inlcuding itself). If I am not understanding you correctly, please let me know. Also it would be helpful to get complete code that you currently have.

    Cheers.

  • skiltz 501 posts 701 karma points
    Oct 07, 2009 @ 04:09
    skiltz
    0

    <xsl:if test="$currentPage/ancestor-or-self::node/@id = 1122">
    </xsl:if>

  • Amir Khan 1199 posts 2567 karma points
    Oct 07, 2009 @ 04:22
    Amir Khan
    0

    Guys, thank you for your help. What i ended up doing was using skiltz code but using a Macro parameter to determine the id, seems to be working great. Basically my problem was that my navigation was complicated enough style-wise that I wanted to hard-code the top-level, but still wanted the scalability of a dymanically-created sub-navigation, this is working very nicely so far.

     

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

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="3"/>
    <xsl:variable name="source" select="/macro/source"/>

    <xsl:template match="/">

    <!-- The fun starts here -->
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = $source">

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
    <ul>
    <li>
    <a href="{umbraco.library:NiceUrl(@id)}">
    <xsl:value-of select="string(data [@alias='page-title'])" />
    </a>
    </li>
    </ul>
    </xsl:for-each>
    </xsl:if>

    </xsl:template>

    </xsl:stylesheet>
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies