Copied to clipboard

Flag this post as spam?

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


  • Rik Helsen 670 posts 873 karma points
    Jul 26, 2010 @ 16:00
    Rik Helsen
    0

    how do i check if a node has children in 4.5 ?

    I'm trying to figure out how to check if a node has children in xslt in 4.5 schema...

    In this navigation xslt:

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

    <!-- Input the documenttype you want here -->
    <xsl:variable name="level" select="2"/>

    <xsl:template match="/">
    <!-- The fun starts here -->
      <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:if test="$currentPage/@id = current()/@id or $currentPage/../@id = current()/@id or $currentPage/../../@id = current()/@id">
          <!-- output navigation Title -->
          <a class="leftnavtitle" href="{umbraco.library:NiceUrl(@id)}">
            <xsl:value-of select="@nodeName"/>
          </a>
          <ul>
            <!-- 1st navigation items -->
            <xsl:for-each select="./child::* [@isDoc]">
              <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"></xsl:if>
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}">
                   <xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">selected</xsl:attribute></xsl:if>
                  <xsl:value-of select="@nodeName"/>a: <xsl:value-of select="count(./descendant/* [@isDoc])"/>
                </a>
             
              <!--output 2nd level nevigation items -->
                <xsl:if test="$currentPage/@id = current()/@id or $currentPage/../@id = current()/@id or $currentPage/../../@id = current()/@id">
             
                  <ul>
                    <!--output 3rd level nevigation items -->
                    <xsl:for-each select="./child::* [@isDoc]">
             
                    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"></xsl:if>
                    <li>
                      <a href="{umbraco.library:NiceUrl(@id)}">
                        <xsl:if test="@id = $currentPage/@id"><xsl:attribute name="class">selected</xsl:attribute></xsl:if>
                       <xsl:value-of select="@nodeName"/>b: <xsl:value-of select="count(./descendant/* [@isDoc])"/>
                      </a>
                    </li>
                    </xsl:for-each>
                  </ul>
                </xsl:if>
                <!--end of 4th level children -->
                </li>
              </xsl:for-each>
            </ul>
          </xsl:if>
        </xsl:for-each>
    </xsl:template>

    </xsl:stylesheet>

    This line always returns 0:

    <xsl:value-of select="count(./descendant/* [@isDoc])"/>
  • Rik Helsen 670 posts 873 karma points
    Jul 26, 2010 @ 16:13
    Rik Helsen
    1

    appears to be this syntax:

     

    count(current()/child::* [@isDoc]) &gt; 0 
  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Jul 26, 2010 @ 16:28
    Lee Kelleher
    0

    Hi Rik,

    You don't even need the "current()/child::" part, you can just use "*[@isDoc]".  Also if you are testing this in an <xsl:if>, you don't need the count - the XPath with just evaluate the nodeset, like so...

    <xsl:if test="*[@isDoc]">
        ...
    </xsl:if>

    Cheers, Lee.

  • Rik Helsen 670 posts 873 karma points
    Jul 26, 2010 @ 16:29
    Rik Helsen
    0

    Thanks Lee, i'll clean up some more ;)

  • John Philip 21 posts 41 karma points
    Jul 21, 2011 @ 11:29
    John Philip
    0

    Thanks Rik and Lee

    That was just what I was looking for!

Please Sign in or register to post replies

Write your reply to:

Draft