Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Aug 29, 2012 @ 22:35
    Steve
    0

    Can't Use Function "exists()" - Alternatives?

    I need to test the top level nodes in my navigation to see if they have children and if they don't assign a link to them. But, at the same time all children from the top level nodes that have children themselves need to have a link assigned to them. 

    I was using the code below with the <xsl:when test="count($node/* [@isDoc and string(umbracoNaviHide) != '1'])" but it takes all the child nodes that have children and removes it's link.

    See my page here:https://edit-www.rose-hulman.edu/offices-services/alumni-affairs-2.aspx

    I tried to use a more logical approach with the test="exists(/parent/$node/*  [@isDoc and string(umbracoNaviHide) != '1'])" but "exists()" doesn't exist in xslt 1.0

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

    <xsl:template match="/">
      <xsl:variable name="home" select="$currentPage/ancestor-or-self::Category2HomePage" />
      <xsl:variable name="nav" select="$home/*[@isDoc and string(umbracoNaviHide)!='1']" />
      <ul>
        <xsl:if test="string($home/useAlternateNavigation) = '1'">
          <xsl:attribute name="class">alt-nav</xsl:attribute>
        </xsl:if>
        <xsl:for-each select="$nav">
          <li>
            <!-- this craziness allows IE to lay subnavs on top of top nav elements if they break onto two lines -->
            <xsl:attribute name="style">z-index:<xsl:value-of select="count($nav)-position()+1" />;</xsl:attribute>
            <xsl:attribute name="class">
              <xsl:if test="$currentPage/ancestor-or-self::*[@isDoc and name()!='Category2HomePage' and @id=current()/@id]">
                <xsl:text>active</xsl:text>
              </xsl:if>
              <xsl:text</xsl:text>
              <xsl:if test="count($nav)=position()">
                <xsl:text>last</xsl:text>
              </xsl:if>
            </xsl:attribute>
            <xsl:call-template name="node-link-with-span">
              <xsl:with-param name="node" select="current()" />
            </xsl:call-template>
            
            <xsl:variable name="subnodes" select="* [@isDoc and string(umbracoNaviHide)!='1']" />
            <xsl:if test="$subnodes">
              <ul>
                <xsl:for-each select="$subnodes">
                  <li>
                    <xsl:if test="position()=1">
                      <xsl:attribute name="class">first</xsl:attribute>
                    </xsl:if>
                    <xsl:call-template name="node-link-with-span">
                      <xsl:with-param name="node" select="current()" />
                    </xsl:call-template>
                  </li>
                </xsl:for-each>
              </ul>
            </xsl:if>
          </li>
        </xsl:for-each>
      </ul>

      <xsl:if test="string($home/useAlternateNavigation) != '1'">
        <img src="/static/phase2/tabNavBorderBottom.jpg" class="tabBorder" />
      </xsl:if>
    </xsl:template>
        
    <xsl:template name="node-link-with-span">
      <xsl:param name="node" />
      
      <xsl:if test="string($node) != ''">
       <a>
              <xsl:attribute name="href">
                <xsl:choose>
                  <xsl:when test="count($node/*[@isDoc and string(umbracoNaviHide) != '1'])">
                    <xsl:text>javascript://</xsl:text>
                  </xsl:when>
                  <xsl:when test="$node[name() = 'ExternalLink']">
                    <xsl:value-of select="$node/url" />
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="umbraco.library:NiceUrl($node/@id)" />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
              
              <span>
                <xsl:call-template name="node-name">
                  <xsl:with-param name="node" select="$node" />
                </xsl:call-template>
              </span>
            </a>
        
      </xsl:if>
    </xsl:template>
        
    <!-- A template to output the correct name for a given node. Better than copy/pasting this code all over the place -->
    <xsl:template name="node-name">
      <xsl:param name="node" />
      
      <xsl:if test="string($node) != ''">
        <xsl:choose>
          <xsl:when test="$node/pageTitle != ''">
            <xsl:value-of select="$node/pageTitle"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$node/@nodeName"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:if>
    </xsl:template>

    </xsl:stylesheet>

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Aug 30, 2012 @ 11:23
    Lee Kelleher
    0

    Hi Steve,

    Try it without the count() or exists().

    <xsl:when test="$node/*[@isDoc and string(umbracoNaviHide) != '1']">

    If the nodeset is returned, then it's deemed true, otherwise false.

    Cheers, Lee.

  • Steve 472 posts 1216 karma points
    Aug 30, 2012 @ 21:17
    Steve
    0

    Thanks that works, but what would I add to the test for only top level parent nodes with children?

  • 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