Copied to clipboard

Flag this post as spam?

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


  • Chau 66 posts 97 karma points
    Sep 25, 2009 @ 17:30
    Chau
    0

    Is there a better way to write this?

    4.02, asp3.5, winxp, iis5.1

    This is my first xslt. It works fine but I was wondering if there was a way to optimize the code. Mostly I am concern with the xsl:choose statement that defines how I am going to display my inline elements based upon whether or not the page has a child node or not. Thanks in advanced.

     <?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"
        exclude-result-prefixes="msxml umbraco.library">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
    <!-- update this variable on how deep your navigation should be -->
    <xsl:variable name="maxLevel" select="5"/>
    <xsl:template match="/">
     <div id="toolbar">
      <div id="menu_container">
       <ul id="pmenu">
        <xsl:call-template name="drawNodes"> 
         <xsl:with-param name="parent" select="$currentPage/ancestor-or-self::node [@level=1]"/> 
        </xsl:call-template>
       </ul>
      </div>
     </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)">
      <xsl:for-each select="$parent/node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel]">
       <xsl:choose>
        <xsl:when test="count(./node) &gt; 0">
         <li class="drop">
          <a href="{umbraco.library:NiceUrl(@id)}">
           <xsl:value-of select="@nodeName"/>
          </a> 
          <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel]) &gt; 0">  
           <ul>
            <xsl:call-template name="drawNodes">   
             <xsl:with-param name="parent" select="."/>   
            </xsl:call-template> 
           </ul>
          </xsl:if>
         </li>
        </xsl:when>
        <xsl:otherwise>
         <li class="nodrop">
          <a href="{umbraco.library:NiceUrl(@id)}">
           <xsl:value-of select="@nodeName"/>
          </a> 
          <xsl:if test="count(./node [string(./data [@alias='umbracoNaviHide']) != '1' and @level &lt;= $maxLevel]) &gt; 0">  
           <ul>
            <xsl:call-template name="drawNodes">   
             <xsl:with-param name="parent" select="."/>   
            </xsl:call-template> 
           </ul>
          </xsl:if>
         </li>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:for-each>
     </xsl:if>
    </xsl:template>
    </xsl:stylesheet>

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Sep 25, 2009 @ 17:51
    Douglas Robar
    0

    Looks like a fine way to handle it to me.

    XSLT is amazingly fast, even in what appears to be non-optimized code. You can see how long it takes to run this macro by adding ?umbDebugShowTrace=true on the querystring of the page that displays the result of this macro. I bet you're looking at a few hundredths or possibly thousandths of a second.

    cheers,
    doug.

Please Sign in or register to post replies

Write your reply to:

Draft