Copied to clipboard

Flag this post as spam?

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


  • Why is Umbraco so difficult 3 posts 23 karma points
    Jan 23, 2012 @ 14:14
    Why is Umbraco so difficult
    0

    Customising sitemap.xslt

    I have been tasked with 'fixing' a bug in Umbraco whereby 'folder' pages are being shown as hyperlinks in the sitemap page. I have had a crack at both the razor and xslt versions of these sitemap pages but for the life of me I cannot get it to work. All I want to simpy do is if the page in the sitemap tree is a folder type then show it's name as text and if it is a page type then show it's name with a link to the page. I even tried using a custom propert instead called showAsLinkInSitemap with a true/false value to for each node (folder/page) but even this does not work, I just get nothing!

    Anyway, here's what I've tried:

    <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]">
    <li>  
      <xsl:if test="string(showAsLinkInSitemap) = '1' or string(showAsLinkInSitemap) = 'null'">
        <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>
      </xsl:if>
      
      <xsl:if test="string(showAsLinkInSitemap) = '0'">
        <xsl:value-of select="@nodeName"/>
        <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>  
      </xsl:if>   
      
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>

     

    I am a complete amateur when it comes to xslt so no idea how to check for a null value using this language. If anyone could help, at all, I would greatly appreciate it as this has got me totally stumped with what I thought would be such a simple thing to do!


  • Rodion Novoselov 694 posts 859 karma points
    Jan 23, 2012 @ 15:38
    Rodion Novoselov
    0

    Hi. If your "showAsLinkInSitemap" property is defined as a "True/false" property then "showAsLinkInSitemap = 1" should be enough.

  • Why is Umbraco so difficult 3 posts 23 karma points
    Jan 23, 2012 @ 15:43
    Why is Umbraco so difficult
    0

    Hi Rodion,

    Tried what you suggested and just get an xslt error:Unexpected token '=' in the expression.

    It does not seem to like the double equals ==. With just one equal = I do not get ann error but also get nothing else.

     

     

  • Why is Umbraco so difficult 3 posts 23 karma points
    Jan 23, 2012 @ 16:03
    Why is Umbraco so difficult
    0

    I've now worked it out as I've discovered the use of xsl:choose, xsl:when and xsl:otherwise. Here's the new code (put between the li tags):

      <xsl:choose>
      <xsl:when test="string(showAsLinkInSitemap) = '1'">
        <a href="{umbraco.library:NiceUrl(@id)}">
        <xsl:value-of select="@nodeName"/></a>  
      </xsl:when>
      
      <xsl:otherwise>
        <span><xsl:value-of select="@nodeName"/></span>
      </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>

     

    So if the property showAsLinkInSitemap is set to true for the page (or folder) it will show as a hyperlink otherwise it will just show as text in a span tag.

  • 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