Copied to clipboard

Flag this post as spam?

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


  • Joachim 16 posts 36 karma points
    Mar 25, 2013 @ 13:03
    Joachim
    0

    Problems with for-each on nodes

    Hello, I am trying to make a simple link list with the pages that has the showInQuickNavigator = 0

    here is my code 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" exclude-result-prefixes="msxml
    umbraco.library">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <ul class="quicknav">
                <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/ancestor::*"/>
                </xsl:call-template>
            </ul>
        </xsl:template>

        <xsl:template name="drawNodes">
            <xsl:param name="parent"/>
                <xsl:for-each select="$parent/* [@isDoc and string(showInQuickNavigator) = '0']">
                    <li>
         <a style="color: #1745B1; font-weight: bold; text-decoration: none;"> &#187; </a>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="siteName"/>
                        </a>
                    </li>
                <xsl:if test="count(./* [@isDoc and string(showInQuickNavigator) != '1']) &gt; 0">
                 <li>
                  <xsl:call-template name="drawNodes">
                   <xsl:with-param name="parent" select="."/>
                  </xsl:call-template>
                 </li>
                </xsl:if>
                </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>

     

     

    It only works properly when your on the parent/first node, if your under a node then it starts looping thats nodes children, can you guys see anything wrong with my script?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 25, 2013 @ 22:28
    Tom Fulton
    0

    Hi,

    If it works fine on your parent/first (Home?) node, you probably just want to adjust your parent parameter.  Do you want it to start at the Homepage?  You might try something like:

    <xsl:with-param name="parent" select="$currentPage/ancestor::Homepage [@isDoc]"/> <!-- or whatever the alias is of the doctype you want to walk up to -->

    -Tom

  • Joachim 16 posts 36 karma points
    Mar 25, 2013 @ 22:37
    Joachim
    0

    With your code above it fixes the dublications I have gotten, now I only need it to also display the Home

    my content tree is like this:
    Content
     - Home
        -Sub1
            -Sub1.1
            -Sub1.2
            -Sub1.3
                -Sub1.3.1
        -Sub2
        -Sub3

    It displays everthing except the Home

    I wan't it to display the Home, got any advice how to do this?

  • Charles Afford 1163 posts 1709 karma points
    Mar 25, 2013 @ 22:48
    Charles Afford
    0

    Hi, not really read throught this post but i am pretty sure you are after ancestor-or-self (You need to check that synatx) :)  Charlie

  • Charles Afford 1163 posts 1709 karma points
    Mar 25, 2013 @ 22:49
    Charles Afford
    0

    SO :

    <xsl:with-paramname="parent"select="$currentPage/ancestor-or-self::Homepage [@isDoc]"/><!-- or whatever the alias is of the doctype you want to walk up to -->
  • Joachim 16 posts 36 karma points
    Mar 25, 2013 @ 22:53
    Joachim
    0

    Current 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" exclude-result-prefixes="msxml
    umbraco.library">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <ul class="quicknav">
                <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::Homepage"/>
                </xsl:call-template>
            </ul>
        </xsl:template>

        <xsl:template name="drawNodes">
            <xsl:param name="parent"/>
                <xsl:for-each select="$parent/* [string(showInQuickNavigator) = '0']">
                    <li>
         <a style="color: #1745B1; font-weight: bold; text-decoration: none;"> &#187; </a>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="siteName"/>
                        </a>
                    </li>
                <xsl:if test="count(./* [string(showInQuickNavigator) = '0']) &gt; 0">
                  <xsl:call-template name="drawNodes">
                   <xsl:with-param name="parent" select="."/>
                  </xsl:call-template>
                </xsl:if>
                </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>

    It still does not display the Home.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 26, 2013 @ 00:57
    Tom Fulton
    0

    You could change the xpath to:

    <xsl:with-param name="parent" select="$currentPage/ancestor::root [@isDoc]"/>

    This will cause the loop to start at the "Content" node, so the first child will be Home, so it should display then.  Be careful if you have other nodes at level 1 though as they'll be listed also.  You might be better off just listing the Home node manually.

     

  • Joachim 16 posts 36 karma points
    Mar 26, 2013 @ 01:45
    Joachim
    0

    I wan't to add it by node and not hardcode as I want my page to be multi-language.

    Current code is still not working:

    <?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" exclude-result-prefixes="msxml
    umbraco.library">

        <xsl:output method="xml" omit-xml-declaration="yes"/>

        <xsl:param name="currentPage"/>

        <xsl:template match="/">

            <ul class="quicknav">
                <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="$currentPage/ancestor::root [@isDoc]"/>
                </xsl:call-template>
            </ul>
        </xsl:template>

        <xsl:template name="drawNodes">
            <xsl:param name="parent"/>
                <xsl:for-each select="$parent/* [@isDoc and string(showInQuickNavigator) = '0']">
                    <li>
         <a style="color: #1745B1; font-weight: bold; text-decoration: none;"> &#187; </a>
                        <a href="{umbraco.library:NiceUrl(@id)}">
                            <xsl:value-of select="siteName"/>
                        </a>
                    </li>
                <xsl:if test="count(./* [@isDoc and string(showInQuickNavigator) != '1']) &gt; 0">
                 <li>
                  <xsl:call-template name="drawNodes">
                   <xsl:with-param name="parent" select="."/>
                  </xsl:call-template>
                 </li>
                </xsl:if>
                </xsl:for-each>
        </xsl:template>
    </xsl:stylesheet>

  • Charles Afford 1163 posts 1709 karma points
    Mar 26, 2013 @ 09:51
    Charles Afford
    0

    I cannot remember the syntax but you need to start of the node where the level= -1.  That will be the very root above HOME.  Charlie :)

  • Joachim 16 posts 36 karma points
    Mar 26, 2013 @ 10:12
    Joachim
    0

    never mind, got it working with:

    <xsl:with-paramname="parent"select="$currentPage/ancestor::root [@isDoc]"/>

    Just need to change it to ancestor-or-self. thanks everybody.

    So this is solution to take from the root:

    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::root"/>
Please Sign in or register to post replies

Write your reply to:

Draft