Copied to clipboard

Flag this post as spam?

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


  • Brad 94 posts 151 karma points
    Feb 15, 2010 @ 13:25
    Brad
    0

    If no child node, don't output anything?

     

    I have a problem with a bit XSLT that outputs the children of the current page in a nice set of li's and all wrapped up in div which makes it all look nice on the page. Here is the XSLT (just from the interesting bit down)


    <!-- Standard stuff above here removed for the sake of brevity -->
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">

    <div id="smarg">
    <div id="snav">
    <h2>Further Information</h2>
    <ul>

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

    </ul>
    </div>
    </div>
    <div id="sfoot"><!-- Foot --></div>

    </xsl:template>

    The problem is that if there is no child to output, I don't want the divs and stuff around it all to be output at all. 

    It's like I need to put a big IF around it all to test if the for-each is going to loop at all.Is that the solution? How do i do that?

     

     

     

  • Chris Koiak 700 posts 2626 karma points
    Feb 15, 2010 @ 13:29
    Chris Koiak
    1
    
    
    

    I think the count function is what you'll require...


    <!-- Standard stuff above here removed for the sake of brevity -->
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">
    <xsl:variable name="childNodes" select="
    $currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']
    "/>
    <xsl:if test="count($childNodes) > 0">

     <div id="smarg">
           
    <div id="snav">
           
    <h2>Further Information</h2>
           
    <ul>

    <xsl:for-each select="$childNodes/node">
           
    <li>
                   
    <a href="{umbraco.library:NiceUrl(@id)}">
                   
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
                           
    <xsl:attribute name="class">LinkSelected</xsl:attribute>
                   
    </xsl:if>
                           
    <xsl:value-of select="@nodeName"/>
                   
    </a>
           
    </li>
    </xsl:for-each>

           
    </ul>
           
    </div>
    </div>

    </xsl:if>
    <div id="sfoot"><!-- Foot --></div>

    </xsl:template>
  • Brad 94 posts 151 karma points
    Feb 15, 2010 @ 23:17
    Brad
    0

    So obvious when you ask in the right place :)

    Thanks Chris. Worked perfectly.

     

     

  • Chris Koiak 700 posts 2626 karma points
    Feb 15, 2010 @ 23:43
    Chris Koiak
    0

    No problem (remember to mark posts as solved)

  • Brad 94 posts 151 karma points
    Feb 17, 2010 @ 06:57
    Brad
    0

    Sure. Where do I do that? The word 'Solved' only appears in your post on this page.

    Do I just type it?

    "It is Solved"

    I can't even mark your post as Helpful.  I don't have 70 Karma points.

    Thanks again

  • Brad 94 posts 151 karma points
    Feb 17, 2010 @ 06:58
    Brad
    0

    Oops.. I found the Tick...

    My bad

    Solved..

     

     

  • 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