Copied to clipboard

Flag this post as spam?

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


  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Sep 14, 2010 @ 18:49
    Dennis Aaen
    0

    Some sitemap quistions

    Hi

    I'm working on a solution which contained a sitemap. In this context, I have some questions.
    I use a standard sitemap from Umbraco. I'm using version 4.5.1

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="5"/>
    <xsl:template match="/">
    <div id="sitemap">
    <xsl:call-template name="drawNodes"> 
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/> 
    </xsl:call-template>
    </div>
    </xsl:template>
    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
    <ul><xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap][name()!='xx_products'][name()!='xx_cases'][name()!='xx_nyheder'][name()!='xx_medarbejdere']">
    <li> 
      <xsl:value-of select="@level"/>
    <a 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:if>
    </xsl:template>
    </xsl:stylesheet>

    My structure is as follows.

    Level 2 -> Level 3 -> Level 4 and Level 5th

    My question is as follows, how can I exclude Level 4 but still get level 5 out. Level 5 is way under Level 4

    Another question. When I've got the right data, how can I provide different levels classes, so they can have different styles.

    For example, the level one becomes bold with the color black and each of the elements of Level 5 get a - in front of all links and get margin-left on for example 15 px.

    Hope some can help me.

    / Dennis

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Sep 16, 2010 @ 18:34
    Dennis Aaen
    100

    I found a solution to my question, and thought that others might use the answer.

    I solved the problem as follows.

    The way I gave names to the different classes so I could style them using my style sheet was as follows.

     <li class = "level{@level}">

     I should also exclude level 4 but still keep level 5th This prolem I solved this way.

     <xsl:if test="@level !=4">

      <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
         </a>  

      </xsl:if>

    My level 5 should have - in front of all links that I solved with an xsl chose as shown below

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

    So the whole xslt code came to look like this

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <!-- update this variable on how deep your site map should be -->
    <xsl:variable name="maxLevelForSitemap" select="5"/>

    <xsl:template match="/">

    <div id="sitemap">
      <h1><xsl:value-of select="$currentPage/johnsen_sitemap_heading"/></h1>
    <xsl:call-template name="drawNodes">  
    <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::* [@isDoc and @level=1]"/>  
    </xsl:call-template>
    </div>
    </xsl:template>

    <xsl:template name="drawNodes">
    <xsl:param name="parent"/>
    <xsl:if test="umbraco.library:IsProtected($parent/@id, $parent/@path) = 0 or (umbraco.library:IsProtected($parent/@id, $parent/@path) = 1 and umbraco.library:IsLoggedOn() = 1)">
      <ul><xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap][name()!='xx_products'][name()!='xx_cases'][name()!='xx_nyheder'][name()!='xx_medarbejdere']">
      <li class = "level{@level}">

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

      <a href="{umbraco.library:NiceUrl(@id)}">
          <xsl:value-of select="@nodeName"/>
         </a>  

      </xsl:if>
    </xsl:otherwise>
    </xsl:choose>
        
     
      
    <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:if>
    </xsl:template>
    </xsl:stylesheet>

    Hope there are others who can use this answer

    / Dennis

  • 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