Copied to clipboard

Flag this post as spam?

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


  • dominik 711 posts 733 karma points
    Jan 14, 2011 @ 11:31
    dominik
    0

    Navigation count problem

     

    Hello

    Is it possible to count the items inside a navigation?

    I need different <div> blocks for some items.

    So it should be

    for < 8 items

    -- <div id="test1">

    for > 8 < 16 items

    -- <div id="test2">

     

    But everytime i try this there is an error inside my xslt file saying that the div is not allowed.


    Can somebody help?

     

  • skiltz 501 posts 701 karma points
    Jan 14, 2011 @ 11:52
    skiltz
    0

    You'll probably need to post your xslt.  Also make sure you are closing you div tag. But yes counting is definetly possible.

  • dominik 711 posts 733 karma points
    Jan 14, 2011 @ 12:09
    dominik
    0

    Ok here it is:

    This does not work properly. Another problem is that in the top-sub-2 menu the items which are in top-sub-1 menu should not appear.


     



       
    <xsl:if test="count(current()/* [@isDoc]) > 0">
                  <div class="top-sub">
                      <xsl:if test="position() > 0 and position() &lt; 7
    ">
                         <div class="top-sub-1">
                           <ul>
                             <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                               <li>
                                 <xsl:if test="position() > 0">
                                     <xsl:attribute name="class">top-sub-1</xsl:attribute>
                                 </xsl:if>
                                 <xsl:if test="position() = 1">
                                   <h2>
                                     <a href="{umbraco.library:NiceUrl(@id)}">
                                     &gt; <xsl:value-of select="@nodeName"/>
                                     </a>
                                   </h2>
                                 </xsl:if>
                                 <xsl:if test="position() > 1">
                                   <a href="{umbraco.library:NiceUrl(@id)}">
                                   &gt; <xsl:value-of select="@nodeName"/>
                                   </a>
                                 </xsl:if>
                               </li>
                            </xsl:for-each>
                          </ul>
                        </div>
                       </xsl:if>
     
                      <xsl:if test="position() > 7 and position() &lt; 14
    ">
                         <div class="top-sub-2">
                           <ul>
                             <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                               <li>
                                 <xsl:if test="position() > 0">
                                     <xsl:attribute name="class">top-sub-2</xsl:attribute>
                                 </xsl:if>
                                 <xsl:if test="position() = 1">
                                   <h2>
                                     <a href="{umbraco.library:NiceUrl(@id)}">
                                     &gt; <xsl:value-of select="@nodeName"/>
                                     </a>
                                   </h2>
                                 </xsl:if>
                                 <xsl:if test="position() > 1">
                                   <a href="{umbraco.library:NiceUrl(@id)}">
                                   &gt; <xsl:value-of select="@nodeName"/>
                                   </a>
                                 </xsl:if>
                               </li>
                            </xsl:for-each>
                          </ul>
                        </div>
                       </xsl:if>
       
                  </div>  
                </xsl:if>
  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 14, 2011 @ 14:20
    Dirk De Grave
    0

    Post your complete xslt cause it's not clear where you start from (where's current() coming from...)

     

    Cheers,

    /Dirk

  • dominik 711 posts 733 karma points
    Jan 14, 2011 @ 14:36
    dominik
    0
    <?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"/>
        <!-- Input the documenttype you want here -->
        <xsl:variable name="level" select="1"/>
     
        <xsl:template match="/">
       
        <!-- The fun starts here -->
        <xsl:for-each select="$currentPage/ancestor-or-self::* [@level = $level]/* [string(umbracoNaviHide) != '1' and @isDoc]">
          <div>
            <xsl:attribute name="class"><xsl:value-of select="menuClass"/></xsl:attribute>
           <ul>
            <xsl:attribute name="class">select</xsl:attribute>
              <li>
                <xsl:if test="$currentPage/@id = current()/@id">
                  <xsl:attribute name="class">selected</xsl:attribute>
                </xsl:if>
                <a href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </a>
                
               
    <xsl:if test="count(current()/* [@isDoc]) > 0">
                  <div class="top-sub">
                      <xsl:if test="position() > 0 and position() &lt; 7
    ">
                         <div class="top-sub-1">
                           <ul>
                             <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                               <li>
                                 <xsl:if test="position() > 0">
                                     <xsl:attribute name="class">top-sub-1</xsl:attribute>
                                 </xsl:if>
                                 <xsl:if test="position() = 1">
                                   <h2>
                                     <a href="{umbraco.library:NiceUrl(@id)}">
                                     &gt; <xsl:value-of select="@nodeName"/>
                                     </a>
                                   </h2>
                                 </xsl:if>
                                 <xsl:if test="position() > 1">
                                   <a href="{umbraco.library:NiceUrl(@id)}">
                                   &gt; <xsl:value-of select="@nodeName"/>
                                   </a>
                                 </xsl:if>
                               </li>
                            </xsl:for-each>
                          </ul>
                        </div>
                       </xsl:if>
     
                     <xsl:if test="position() > 7 and position() &lt; 14
    ">
                         <div class="top-sub-2">
                           <ul>
                             <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                               <li>
                                 <xsl:if test="position() > 0">
                                     <xsl:attribute name="class">top-sub-2</xsl:attribute>
                                 </xsl:if>
                                 <xsl:if test="position() = 1">
                                   <h2>
                                     <a href="{umbraco.library:NiceUrl(@id)}">
                                     &gt; <xsl:value-of select="@nodeName"/>
                                     </a>
                                   </h2>
                                 </xsl:if>
                                 <xsl:if test="position() > 1">
                                   <a href="{umbraco.library:NiceUrl(@id)}">
                                   &gt; <xsl:value-of select="@nodeName"/>
                                   </a>
                                 </xsl:if>
                               </li>
                            </xsl:for-each>
                          </ul>
                        </div>
                       </xsl:if>
       
                  </div>  
                </xsl:if>          </li>
          </ul>
          </div>
        </xsl:for-each>
        
      </xsl:template>
     </xsl:stylesheet>
  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 14, 2011 @ 21:04
    Kim Andersen
    0

    Hi Dominik.

    When you want to use the greater than and less than you can't use the "<" and ">" signs. You have to use the "&lt;" and "&gt;" like you have done a couple of times, but not everywhere. Try changing this and see if the XSLT still generates errors.

    /Kim A

  • dominik 711 posts 733 karma points
    Jan 17, 2011 @ 07:57
    dominik
    0

    I didnt get this working.

     

    So what i want to do:

    I have a navigation inside a div for 7 items. After 7 items there should be a new div (with a new class)

    In this way:

     <xsl:if test="position() &gt; 0 and position() &lt; 8">
    <div class="top-sub-1">
               <ul>
                 <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                     <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/>
                         </a></li>
    </xsl:for-each>
    </ul<
    </div>
    </xsl:if>

     <xsl:if test="position() &gt; 7 and position() &lt; 15">
    <div class="top-sub-12">
               <ul>
                 <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                     <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/>
                         </a></li>
    </xsl:for-each>
    </ul<
    </div>
    </xsl:if>



     

    Can anybody help?

     


  • Kim Andersen 1447 posts 2196 karma points MVP
    Jan 17, 2011 @ 22:49
    Kim Andersen
    0

    Hey Dominik

    What's the rendered output of your code?

    I assume that you closed the ul's the right way and not like this: </ul<.

    Did you remember to change this line as well:

    <xsl:if test="count(current()/* [@isDoc]) > 0">

    to this:

    <xsl:if test="count(current()/* [@isDoc]) &gt; 0">

    /Kim A

  • dominik 711 posts 733 karma points
    Jan 18, 2011 @ 08:08
    dominik
    0

    Thanks

    What the problem is

    If i got two arguments the navigation is always using the second if statement.

    So i have to ensure that the first items are not overwritten with the second items

    If I am using the following code and there are three navigation items there should be the first two inside the <div class="top-sub-1">

    and the third one in <div class=top-sub-2> but all three appears in top-sub-2

     

                <xsl:if test="count(current()/* [@isDoc]) &gt; 0">
                  <div class="top-sub">
                       <xsl:if test="position() &gt; 0 and position() &lt; 3">
                  <div class="top-sub-1">
               <ul>
                 <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                     <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/>
                         </a></li>
                 </xsl:for-each>
               </ul>
          </div>
    </xsl:if>

     <xsl:if test="position() &gt; 2 and position() &lt; 15">
          <div class="top-sub-2">
               <ul>
                 <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                     <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/>
                         </a></li>
                 </xsl:for-each>
               </ul>
          </div>
    </xsl:if>

                  </div>  
                </xsl:if>

     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 18, 2011 @ 08:11
    Jan Skovgaard
    0

    Hi Dominik

    Have you tried changing the order in, which the if statements appear? I think that once the first if is met the other one is never hit...

    /Jan

  • dominik 711 posts 733 karma points
    Jan 18, 2011 @ 08:17
    dominik
    0

    Still the same problem

    All items are in the top-sub-2 div

  • dominik 711 posts 733 karma points
    Jan 18, 2011 @ 08:22
    dominik
    0

    I think the problem is that either the first or the second if statement is used but i have to use both. For position 1-2 top-sub-1 and for position > 2 top-sub-2

    But everytime it uses only one if statement 

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 18, 2011 @ 08:29
    Jan Skovgaard
    0

    It makes sense that it only hits the first if sentence since it returns all the nodes that do have children and therefore the 2. if is never hit. Therefore please try to switch them around if you have not done so already.

    Otherwise try making a choose instead like

    <xsl:choose>
    <xsl:when test="your count that checks between 2 and 15"><!--code here--></xsl:when>
    <xsl:when test="your count that checks if greater than 0"><!--code here--></xsl:when>
    </xsl:choose>

    In the above example I have made the switch I'm talking about since I'm 100% sure that in a choose you will not come to the next when if the first one met is true. So if you started with the greater than 0 condition it would never go to the next check.

    Hope this helps.

    /Jan

  • dominik 711 posts 733 karma points
    Jan 18, 2011 @ 08:36
    dominik
    0

    Hi Jan,

    I will try to make a choose.

    But in which example you made the switch?

     

  • dominik 711 posts 733 karma points
    Jan 18, 2011 @ 08:45
    dominik
    0

    I think the problem is that position is a static number. So if i will search for all items for example the number would be 9. So it is only using the top-sub-2 because it is between 2 and 15

    But it should use only another div box for the first two items 1-2 which are then not displayed in top-sub-2

    top-sub-2 should only handle items 3-15

    here it is inside a choose statement

     

                <xsl:if test="count(current()/* [@isDoc]) > 0">
                  <div class="top-sub">
                  <xsl:choose>
                      <xsl:when test="position() > 2 and position() < 15">
                          <div class="top-sub-2">
                             <ul>
                               <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                                   <li><a href="{umbraco.library:NiceUrl(@id)}">> <xsl:value-of select="@nodeName"/>a>li>
                               xsl:for-each>
                             ul>
                          div>
                      xsl:when>
                      <xsl:when test="position() > 0 and position() < 2">
                        <div class="top-sub-1">
                         <ul>
                           <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                               <li><a href="{umbraco.library:NiceUrl(@id)}">> <xsl:value-of select="@nodeName"/>a>li>
                           xsl:for-each>
                         ul>
                      div>
                      xsl:when>
                  xsl:choose>  
                  div>  
                xsl:if>
  • dominik 711 posts 733 karma points
    Jan 20, 2011 @ 08:57
    dominik
    0

    now i've got a new idea of doing this

    I create a own property called "showInSubNaviBox" and set this to left, middle

    But now every item is displayed in each box

      <xsl:if test="count(current()/* [@isDoc]) &gt; 0">
                  <div class="top-sub">
                    <xsl:if test="current()/* [string(showInSubNaviBox) = 'left' and @isDoc]">
                       <div class="top-sub-1">
                             <ul>
                               <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                                   <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/></a></li>
                               </xsl:for-each>
                             </ul>
                       </div>
                    </xsl:if>
                    <xsl:if test="current()/* [string(showInSubNaviBox) = 'middle' and @isDoc]">
                       <div class="top-sub-2">
                             <ul>
                               <xsl:for-each select="current()/* [string(umbracoNaviHide) != '1' and @isDoc]">
                                   <li><a href="{umbraco.library:NiceUrl(@id)}">&gt; <xsl:value-of select="@nodeName"/></a></li>
                               </xsl:for-each>
                             </ul>
                       </div>
                    </xsl:if>
                   </div>  
                </xsl:if>

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 20, 2011 @ 09:06
    Jan Skovgaard
    0

    Hi Dominik

    Maybe this would be a lot easier if you add two properties of true/false to your master document type called "display in box 1" and "display in box 2".

    That way you can make a check on these properties to decide, which nodes should be displayed where. The above posted code looks way to cumbersome for what youo're trying to achieve.

    I think this could be a pragmatic solution to your problem. However I'm not able to provide you with some examples at the moment. Need to wake up first ;-)

    /Jan

     

  • dominik 711 posts 733 karma points
    Jan 20, 2011 @ 09:09
    dominik
    0

    Where is the difference between Using a textstring  or a true/false to decide in which box the Link should appear?

    In the future there is also a box 3 and box 4 so i do not want to have 4 different properties.

     

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jan 20, 2011 @ 09:49
    Jan Skovgaard
    0

    Hi Dominik

    Ok, in that case it makes sense that you're trying to do it by counting etc.

    If I have some spare time this evening I'll try to dig deeper into it.

    It's much easier to just say that you need the pages with property x set in box 1 and those with property y set in box 2 instead of having to count etc. - You can also do it using a textbox. I just find it more easy to use booleans when it's in fact that you're testing for. But since the suggestion is probably not a solution for you it does not matter :-)

    I'll keep you posted.

    /Jan

  • dominik 711 posts 733 karma points
    Jan 20, 2011 @ 10:06
    dominik
    0

    Thanks for your help

    but why it does not work to use a textstring to decide in which box the link will appear.

    In this case i can use a property dropdown in the documet type with values "box1" "box2" "box3" etc.

    The XSLT has to check if the menupoint uses "box1" as value and put this point under the div container "top-sub-1"

     

Please Sign in or register to post replies

Write your reply to:

Draft