Copied to clipboard

Flag this post as spam?

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


  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jun 03, 2010 @ 15:39
    Jeroen Breuer
    0

    Display nodes while parent has umbracoNaviHide set to true

    Hello,

    I'm using the Google SiteTree XSLT to display a sitemap, but not all the nodes I want to display are shown. I want to show nodes who have umbracoNaviHide set to false even if the parent has this value set to true. Here is the XSLT:

    <?xml version="1.0" encoding="UTF-8"?>
    <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" exclude-result-prefixes="msxml umbraco.library">
    <xsl:output method="html"/>
    <xsl:param name="currentPage"/>
    <xsl:variable name="maxLevelForSitemap" select="8"/>
       <xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" />
    <xsl:template match="/">
    <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')"/>
    
    <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
    
        <url> 
            <loc>
                <xsl:value-of select="$url"/>
            </loc>
            <lastmod>
                <xsl:value-of select="$currentPage/ancestor-or-self::node [@level=1]/@updateDate" />+00:00
            </lastmod>
    
            <changefreq>
                daily
            </changefreq>
    
            <priority>
                0.8
            </priority>
    
        </url>
    
        <xsl:call-template name="drawNodes">  
            <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/>
        </xsl:call-template>
    </urlset>
    </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)">
    
            <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and 
                                @level &lt;= $maxLevelForSitemap]">
                <url xmlns="http://www.google.com/schemas/sitemap/0.84">  
                    <loc>
    
                        <xsl:value-of select="$url"/><xsl:value-of select="umbraco.library:NiceUrl(@id)"/>
                    </loc>
                    <lastmod>
                        <xsl:value-of select="@updateDate" />+00:00
                    </lastmod>
    
                    <!-- optional: changefreq | values: always, hourly, daily, weekly, monthly, yearly, never -->
                    <changefreq>
                        weekly
                    </changefreq>
    
                    <priority>
    
                        0.5
                    </priority>
                </url>
                <xsl:if test="count(./node [string(./data [@alias='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:for-each>
        </xsl:if>
    
    </xsl:template>
    
    </xsl:stylesheet>

    What should I change?

    Jeroen

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jun 03, 2010 @ 21:55
    Chriztian Steinmeier
    0

    Hi Jeroen,

    I'd do it more like this:

    <xsl:stylesheet
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        version="1.0"
        xmlns:umbraco.library="urn:umbraco.library"
        xmlns="http://www.google.com/schemas/sitemap/0.84"
        exclude-result-prefixes="umbraco.library"
    >
    
        <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
        <xsl:param name="currentPage" />
        <xsl:variable name="homePage" select="$currentPage/ancestor-or-self::node[@level = 1]" />
    
        <xsl:variable name="maxLevelForSitemap" select="8" />
        <xsl:variable name="url" select="concat('http://', umbraco.library:RequestServerVariables('HTTP_HOST'))" />
    
        <!-- Uncomment if you need protection stuff -->
        <!-- <xsl:variable name="isLoggedOn" select="umbraco.library:IsLoggedOn()" /> -->
    
        <xsl:template match="/">
            <!-- Set XML as output MIME-Type -->
            <xsl:value-of select="umbraco.library:ChangeContentType('text/xml')" />
    
            <urlset>
                <!-- Apply templates to the Home page and its descendants within the specified level -->
                <xsl:apply-templates select="$homePage/descendant-or-self::node[@level &lt;= $maxLevelForSitemap]" />
            </urlset>
    
        </xsl:template>
    
        <!-- Template for the Home page -->
        <xsl:template match="node[@level = 1]">
            <url>
                <loc>
                    <xsl:value-of select="$url" />
                </loc>
                <lastmod>
                    <xsl:value-of select="concat(@updateDate, '+00:00')" />
                </lastmod>
                <changefreq>daily</changefreq>
                <priority>0.8</priority>
            </url>
        </xsl:template>
    
        <!-- Template for all other pages -->
        <xsl:template match="node">
            <!-- Uncomment if you need protection stuff -->
            <!-- <xsl:variable name="isProtected" select="umbraco.library:IsProtected(@id, @path)" /> -->
            <!-- <xsl:if test="not($isProtected) or ($isProtected and $isLoggedOn)"> -->
                <url>
                    <loc>
                        <xsl:value-of select="concat($url, umbraco.library:NiceUrl(@id))" />
                    </loc>
                    <lastmod>
                        <xsl:value-of select="concat(@updateDate, '+00:00')" />
                    </lastmod>
                    <changefreq>weekly</changefreq>
                    <priority>0.5</priority>
                </url>
            <!-- Uncomment if you need protection stuff -->
            <!-- </xsl:if> -->
        </xsl:template>
    
        <!-- Do not process hidden pages -->
        <xsl:template match="node[data[@alias = 'umbracoNaviHide'] = 1]" />
    
    </xsl:stylesheet>
    
    

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft