Copied to clipboard

Flag this post as spam?

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


  • MRavensholt 19 posts 39 karma points
    Feb 16, 2011 @ 12:22
    MRavensholt
    0

    XSLT Navigation

    Hi there...

    I'm creating this navigation in xslt, and I'm using an unordered list (ul>li) to do this.

    <xsl:if test="count(child::*) > 0">
                    <ul>
                      <xsl:for-each select="$startItem/*[@isDoc and name() !='IntranetFolder']">
                        <xsl:variable name="leftnav" select="current()/hideFromLeftMenu"/>
                        <xsl:if test="($leftnav != '1')">
                          <li>

     

    the above works , as long as the "ul" has children that have the hideFromLeftMenu set to false ('0').

    I was wondering, if it is possible to check for the hideFromLeftMenu before the xsl:for-each loop ? Maybe check for it in the count?

     

    Best regards
    Martin

     

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Feb 16, 2011 @ 12:32
    Chriztian Steinmeier
    0

    Hi Martin,

    Rule of thumb is to test with the same conditions - but you can use an intermediate variable to improve readability (and remove duplication), e.g.:

    <xsl:variable name="nodes" select="$startItem/*[@isDoc][not(self::IntranetFolder)][not(hideFromLeftMenu = 1)]" />
    <xsl:if test="$nodes">
        <ul>
            <xsl:for-each select="$nodes">
                <li>
                    <!-- etc... -->
                </li>
            </xsl:for-each>
        </ul>
    </xsl:if>
    

    /Chriztian

  • MRavensholt 19 posts 39 karma points
    Feb 16, 2011 @ 13:37
    MRavensholt
    0

    I'm not sure .... I'm only interested in printing the <ul> if count(children) > 0 and at least one of the children has hideFromLeftMenu = 0 :)

    Would the above solution work for this scenario?

  • MRavensholt 19 posts 39 karma points
    Feb 16, 2011 @ 13:47
    MRavensholt
    0

    It seems like your solution worked :D

    Thanks alot

     

    Best regards
    Martin.

Please Sign in or register to post replies

Write your reply to:

Draft