Copied to clipboard

Flag this post as spam?

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


  • Brad Slander 5 posts 25 karma points
    May 20, 2010 @ 14:29
    Brad Slander
    0

    Traversing nodes

    Hi folks,

    I am new to umbraco and xslt and I am having a problem with rendering the correct nodes to screen. My Content tree consists of:

    Content

    -Home

    --Sub Node - Folder

    ---Archive Node - Folder -- node id=1379

    ----January - Folder

    -------Page Node

    -------Page Node

    ----February Node - Folder

    -------Page Node

    -------Page Node

    What I require for each month to be rendered as the header and the page nodes as a drop down list (This has been set up using a jquery accordian).

    The problem I am getting is that the January folder is being rendered twice and the 4 page nodes are rendered underneath each January heading. Its quite obvious I am missing the point somewhere with XSLT and XPATH. Could some one tell me where I am going wrong please. My XSLT file is:

    <xsl:param name="currentPage"/>
    <xsl:variable name="startnode" select="umbraco.library:GetXmlNodeById(1379)"/>
    <xsl:template match="/">

    <div class="event-details">
    <h1><xsl:value-of select="$currentPage/@nodeName"/></h1>
    <div class="function-wrapper">
    <xsl:for-each select="$startnode/node">
    <h2 class="trigger"><a href="#"><xsl:value-of select="$startnode/node/@nodeName"/></a></h2>
    <div class="toggle_container">
     <div class="block">
      <ul class="list">
      <xsl:for-each select="$startnode/node/node">
       <li>
        <a href="{umbraco.library:NiceUrl(@id)}" title="">
        <xsl:if test="node!='false'">
         <xsl:attribute name="title"><xsl:value-of select="@nodeName" /></xsl:attribute>
        </xsl:if>
       <xsl:value-of select="@nodeName" /></a>
       </li>
      </xsl:for-each>
      </ul>
     </div>
    </div>
    </xsl:for-each>
    </div><!--end function-wrapper-->
    </div><!--end event-details-->
    </xsl:template>

     

    Thank you

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 20, 2010 @ 14:39
    Sebastiaan Janssen
    0

    You for-each contains a reference to $startNode/node a few times, you should not repeat them over there. I just tested this version and it works fine:

    <xsl:for-each select="$startnode/node">
          <h2 class="trigger">
            <a href="#">
              <xsl:value-of select="@nodeName"/>
            </a>
          </h2>
          <div class="toggle_container">
            <div class="block">
              <ul class="list">
                <xsl:for-each select="node">
                  <li>
                    <a href="{umbraco.library:NiceUrl(@id)}" title="">
                      <xsl:if test="node!='false'">
                        <xsl:attribute name="title">
                          <xsl:value-of select="@nodeName" />
                        </xsl:attribute>
                      </xsl:if>
                      <xsl:value-of select="@nodeName" />
                    </a>
                  </li>
                </xsl:for-each>
              </ul>
            </div>
          </div>
        </xsl:for-each>
  • Brad Slander 5 posts 25 karma points
    May 20, 2010 @ 14:47
    Brad Slander
    0

    Works a treat. Thank you for this. It has also got my head round what is needed.

    Thanks again

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    May 20, 2010 @ 15:02
    Sebastiaan Janssen
    0

    No problem, would you be so kind as to mark my answer as the one that solved your problem? Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft