Copied to clipboard

Flag this post as spam?

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


  • eddy 43 posts 64 karma points
    Sep 02, 2010 @ 12:18
    eddy
    0

    List subsections and their child articles

    I'm trying to get to grips with XSLT and it's certainly a challenge. I've read lots of forum posts and watched videos but cannot create a relatively simple list.

    Within a main section on my site I would like to list all the subsections and then present their child articles as a nested list. I have managed to present the subsections but the child articles are not being grouped within their subsections. At the moment the child articles are listed in all subsections. 

    How can I group them? Here is my code: 

    <xsl:template match="/">

     

      <xsl:for-each select="$currentPage/descendant::Subsection [@isDoc and string(umbracoNaviHide) != '1']">

      <h2><xsl:value-of select="@nodeName"/></h2>
      <xsl:for-each select="$currentPage/descendant::SimpleTextPage">
      <ul>
      <li>
        <href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
      </li>
      </ul>
      </xsl:for-each>
    </xsl:for-each>
    </xsl:template>

    I'm guessing I need to add something here: 

    <xsl:for-each select="$currentPage/descendant::SimpleTextPage">

    but every example I look at seems to offer a different solution.

    thanks, Eddy

  • eddy 43 posts 64 karma points
    Sep 02, 2010 @ 14:59
  • eddy 43 posts 64 karma points
    Sep 02, 2010 @ 16:03
    eddy
    0

    I've managed to get the list using various forum topics but particularly Dougs advice above. However in his example all items are listed in li tags as links.

    I would like to style level 3 Items with a h2 tag and the child nodes with an anchor tag. Is it possible to write an if statement for example; if level 3 then <h2>...</h2>, if level 4 then <li><a>...</a></li>? 

    Heres my code:

    <xsl:variable name="maxLevelForSitemap" select="4"/>
    <xsl:variable name="source" select="/macro/source"/>
    <xsl:template match="/">
    <div id="sitemap"
     <xsl:call-template name="drawNodes">  
        <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeById($source) "/>
     </xsl:call-template>
    </div>
    </xsl:template>
    <xsl:template name="drawNodes">
      <xsl:param name="parent"/>
        <ul>
          <!-- level is a standard attribute on every node -->        
           <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]">
              <li>
                <href="{umbraco.library:NiceUrl(@id)}">
                  <xsl:value-of select="@nodeName"/>
                </a>
                <xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap]) &gt; 0">
                  <xsl:call-template name="drawNodes">
                    <xsl:with-param name="parent" select="."/>
                  </xsl:call-template>  
                </xsl:if
              </li>
            </xsl:for-each>
          </ul>
      </xsl:template>

    Any help really appreciated as I'm slowly losing the will to live.

    thanks.

  • Rik Helsen 670 posts 873 karma points
    Sep 02, 2010 @ 16:43
    Rik Helsen
    0

    just above

           <a href="{umbraco.library:NiceUrl(@id)}">

    Add something like


    <xsl:choose>
    <xsl:when test="./@level = 3">
    <h2>
    </xsl:when>
    <xsl:when test="./@level = 4">
    <h3>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>

    And just after </a>:


    <xsl:choose>
    <xsl:when test="./@level = 3">
    </h2>
    </xsl:when>
    <xsl:when test="./@level = 4">
    </h3>
    </xsl:when>
    <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>

    You'll probably need to play with the levels (which level corresponds with wich heading)

  • eddy 43 posts 64 karma points
    Sep 02, 2010 @ 17:03
    eddy
    0

    Thank for the tip Rik however it breaks with the error:

    System.Xml.XmlException: Das 'h2'-Anfangstag in Zeile '38' stimmt nicht mit dem Endtag von 'xsl:when' überein. Zeile 39, Position 3. 

     the h2 tag doen't match the  </xsl:when> tag.

     

  • eddy 43 posts 64 karma points
    Sep 02, 2010 @ 17:16
    eddy
    0

    I got it working using the code below. Thanks for the assistance!

     <xsl:choose>
                <xsl:when test="./@level = 3">
                  <h2>
                    <xsl:value-of select="@nodeName"/>
                  </h2>
                </xsl:when
                <xsl:when test="./@level = 4">
                  <href="{umbraco.library:NiceUrl(@id)}">
                    <xsl:value-of select="@nodeName"/>
                  </a>
                </xsl:when>
                <xsl:otherwise>
    </xsl:otherwise>
    </xsl:choose>

     

     

  • 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