Copied to clipboard

Flag this post as spam?

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


  • syn-rg 282 posts 425 karma points
    Nov 18, 2010 @ 02:33
    syn-rg
    0

    Hide doctype from sitemap

    I've been trying to hide a doctype from my site map, but when I do it causes the entire sitemap to disappear.

    This is the offending line of code:

    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap and @nodeTypeAlias != 'HomeImage']">

    The only code that will display my site map is the following:

    <?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="4"/>

    <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]">
        
    <li>  
    <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>

    Does anyone have a solution?

    JV

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 18, 2010 @ 03:25
    Tom Fulton
    1

    Hi JV

    There is no more @nodeTypeAlias in the new 4.5 schema.  The nodes are now named with their doctype alias, ie <HomeImage id="..">.  You can check for it using name() - this should work:

    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap and name() != 'HomeImage']">

    -Tom

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 18, 2010 @ 03:28
    Tom Fulton
    0

    Also, just as a side note, typically the pages I don't want to show in the sitemap/nav don't have an associated template (they aren't meant to be displayed as pages), so I check for them all using something like this.  Easier than adding a bunch of conditions for each doctype

    string(@template) != '0'

  • syn-rg 282 posts 425 karma points
    Nov 18, 2010 @ 04:15
    syn-rg
    0

    Thanks Tom!

    The first option works well. The pages I have don't have templates either so I tried implementing the following:

    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level <= $maxLevelForSitemap and string(@template) != '0']">

    But it caused my sitemap to display incorrectly, everything in the red box should all be at the same level.

     

    What would the code be if I had to add another doctype to be hidden?

    <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap and name() != 'HomeImage']">
  • Tom Fulton 2030 posts 4998 karma points c-trib
    Nov 18, 2010 @ 04:44
    Tom Fulton
    2

    Hi - Sorry, you also need to duplicate the conditions in the xsl:if statement below the loop to fix that.  Otherwise it calls the template again and writes a new UL for child nodes, which will be empty according to the for-each.

     <xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1' and @level &lt;= $maxLevelForSitemap and string(@template) != '0']">
       
    <li>  
    <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 and string(@template) != '0']) &gt; 0">  
    <xsl:call-template name="drawNodes">    

    If you just want to do it by doctypes, just keep adding to the conditions:

    ... and name() != 'HomeImage' and name() != 'AnotherType' ...

    ..etc.  You will also need to add these conditions to the xsl:if statement as shown above.  If you have a lot of doctypes you might be able to put them all in a comma separated string or XML variable and use something like contains() to check, but this is just a quick/simple way :)

     

     

  • syn-rg 282 posts 425 karma points
    Nov 18, 2010 @ 04:53
    syn-rg
    0

    Thanks Tom, you're a champ!

    It works like a charm! I'll be using a combination of the @template and doctype alias as some of the pages I want hidden from the sitemap will include templates.

    Here's my final code:

    <?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="6"/>

    <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 and string(@template) != '0' and name() !=
    'HomeImage']"
    >
        
    <li>  
    <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 and string(@template) != '0' and name() !=
    'HomeImage']) &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>
Please Sign in or register to post replies

Write your reply to:

Draft