Copied to clipboard

Flag this post as spam?

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


  • Casper Søgaard 6 posts 26 karma points
    Sep 07, 2011 @ 16:54
    Casper Søgaard
    0

    Use two columns if items exceeds 7

    Hi all,

    I’ve been trying to get this to work for a while now.

    I want to print out my navigation in two columns if the count of items exceeds 7. Creating a new div-class "megadropcol".

    So far I got this to work – it prints out all items in just one column:

    <!-- Drop Down Menu -->
                <xsl:if test="count(./* [@isDoc and
    string(umbracoNaviHide) != '1']) &gt; 0">
                    <div class="megadrop" style="display: none;">
                        <div class="megadropContent">
                            <div class="megadropcol">
                                <h3>Megadropheadline1</h3>
                                    <ul>
                                        <xsl:for-each select="./*
    [@isDoc and string(umbracoNaviHide) != '1']">
         
                                      <li>
                                               
    <xsl:if test="$currentPage/ancestor-or-self::node/@id
    = current()/@id">
                                                   
    <xsl:attribute name="class">current</xsl:attribute>
                                               
    </xsl:if>
                                               
    <a href="{umbraco.library:NiceUrl(@id)}">
                                                   
    <xsl:value-of select="@nodeName"/>
                                                </a>
                                            </li>
                                        </xsl:for-each>
                                    </ul>
                                </div>
                            </div>
                        </div>
                </xsl:if>
                </li>
                <!-- End of Drop Down Menu
    -->

     

    I’m new to XSLT so bear with me J

    Thanks in advance.

     

  • Euan Rae 105 posts 134 karma points
    Sep 08, 2011 @ 11:52
    Euan Rae
    0

    you could use something like <xsl:if test="position() &lt; 7 "> to restrict the number of <li> items rendered out.

  • Casper Søgaard 6 posts 26 karma points
    Sep 08, 2011 @ 11:57
    Casper Søgaard
    0

    I've tried that one but no luck:

     

    <!-- Drop Down Menu -->
                <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
                    <div class="megadrop" style="display: none;">
                      <div class="megadropContent">
                        
                        <!--Start less than 7-->
                              
                              <xsl:if test="position() &lt;= 7 ">
                                  <div class="megadropcol">
                                      <h3>Megadropheadline1</h3>
                                      <ul>
                                          <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                                              <li>
                                                  <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                                      <xsl:attribute name="class">current</xsl:attribute>
                                                  </xsl:if>
                                                  <a href="{umbraco.library:NiceUrl(@id)}">
                                                      <xsl:value-of select="@nodeName"/>
                                                  </a>
                                              </li>
                                          </xsl:for-each>
                                      </ul>
                                  </div>
                              </xsl:if>
                        <!--End less than 7-->

                        <!--Start greater than 7-->
                              <xsl:if test="position() &gt; 7 ">
                                  <div class="megadropcol">
                                      <h3>Megadropheadline1</h3>
                                      <ul>
                                          <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                                              <li>
                                                  <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                                      <xsl:attribute name="class">current</xsl:attribute>
                                                  </xsl:if>
                                                  <a href="{umbraco.library:NiceUrl(@id)}">
                                                      <xsl:value-of select="@nodeName"/>
                                                  </a>
                                              </li>
                                          </xsl:for-each>
                                      </ul>
                                  </div>
                              </xsl:if>
                            
                        <!--End greater that 7-->
                          
                      </div>
                    </div>
                </xsl:if>
                </li>
                <!-- End of Drop Down Menu -->
  • Euan Rae 105 posts 134 karma points
    Sep 08, 2011 @ 12:01
    Euan Rae
    0

    The reason that's not working is because you're putting the line 

    <xsl:if test="position() &lt;=7> outside the <xsl:for-each loop/>

    the position() function only works inside the for-each loop

  • Casper Søgaard 6 posts 26 karma points
    Sep 08, 2011 @ 12:42
    Casper Søgaard
    0

    Thank you :-) That worked.

     

    If anyone want the solution:

    <!--Start less than 7-->
                        <div class="megadropcol">
                          <h3>Megadropheadline1</h3>
                            <ul>
                              <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                                <xsl:if test="position() &lt;= 7 ">
                                  <li>
                                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                      <xsl:attribute name="class">current</xsl:attribute>
                                    </xsl:if>
                                    <a href="{umbraco.library:NiceUrl(@id)}">
                                      <xsl:value-of select="@nodeName"/>
                                    </a>
                                  </li>  
                              </xsl:if>
                            </xsl:for-each>
                          </ul>
                        </div>
                        <!--End less than 7-->

                        <!--Start greater than 7-->
                        <div class="megadropcol">
                          <h3>Megadropheadline1</h3>
                            <ul>
                              <xsl:for-each select="./* [@isDoc and string(umbracoNaviHide) != '1']">
                                <xsl:if test="position() &gt;= 7 ">
                                  <li>
                                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                                      <xsl:attribute name="class">current</xsl:attribute>
                                    </xsl:if>
                                    <a href="{umbraco.library:NiceUrl(@id)}">
                                      <xsl:value-of select="@nodeName"/>
                                    </a>
                                  </li>  
                              </xsl:if>
                            </xsl:for-each>
                          </ul>
                        </div>
                        <!--End greater than 7-->

     


  • Euan Rae 105 posts 134 karma points
    Sep 08, 2011 @ 12:48
    Euan Rae
    0

    No worries.

  • 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