Copied to clipboard

Flag this post as spam?

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


  • Craig100 1078 posts 2366 karma points c-trib
    Oct 19, 2011 @ 10:41
    Craig100
    0

    Sitemap choose "when" test failure

    Hi,

    I need to modify the XSLT Sitemap map macro so it doesn't link a particular node type.  I've added a choose section. The "When" test always fails and outputs the "otherwise" section. I'm new to XSLT and so I'm having great dificulty getting this right. Any help would be greatly appreciated. Current state of the code is below. 

    Craig

    <?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" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
    
    <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>
    
      <!--if nodeTypeAlias is SideMenuSubSectionHeading then don't make it a link -->
    
      <xsl:choose>
        <xsl:when test="data[@alias = 'SideMenuSubSectionHeading']">          
          <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:when>
        <xsl:otherwise>
          <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:otherwise>
      </xsl:choose>
    
    </li>
    </xsl:for-each>
    </ul>
    </xsl:if>
    </xsl:template>
    </xsl:stylesheet>
  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 19, 2011 @ 11:58
    Dirk De Grave
    0

    you're mixing up two different xml schema's, one used pre v4.5, other from v4.5+

    you should rewrite your xsl:when as

    <xsl:whentest="name(.) = 'SideMenuSubSectionHeading'">

     

    Cheers,

    /Dirk

     

  • Craig100 1078 posts 2366 karma points c-trib
    Oct 19, 2011 @ 13:36
    Craig100
    0

    Perfect, thanks.

    Not being expert in XSLT it's currently beyond me to recognise the difference between the schemas. Therefore when picking up bits and peices from forums and sites it's easy to mess it up.

    Thanks again.

    Craig

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 20, 2011 @ 00:33
    Chriztian Steinmeier
    0

    Hi Craig,

    Another way to ask is using the self:: axis - note that you don't use apostrophes in this case:

    <xsl:when test="self::SideMenuSubSectionHeading">

    The name() function though, is necessary when you need to test against a variable, e.g.:

    <xsl:when test="name(.) = $nameOfDharmaStation">

    /Chriztian

  • 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