Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 13, 2011 @ 22:23
    Fuji Kusaka
    0

    Choose or otherwise

    I have the following statement where i use a GetXmlNodeById to display to display the child nodes if there is any and if not to display a message.

    Am not sure what am doing wrong or missing something.

    <xsl:for-each select="umbraco.library:GetXmlNodeById($source)/*[@isDoc and string(umbracoNaviHide) != '1']">
              <xsl:choose>
                  <xsl:when test="count(./*[@isDoc and string(umbracoNaviHide) != '1']) &gt;0">
                    <xsl:value-of select="
    somevalue"/>                          
                 </xsl:when>
                  <xsl:otherwise>
                        Do something else 
                   </xsl:otherwise>
            </xsl:choose>               
    </xsl:for-each>
  • Jan Skovgaard 11258 posts 23500 karma points MVP 7x admin c-trib
    Oct 13, 2011 @ 22:31
    Jan Skovgaard
    0

    Hi Fuji

    What is the problem?

    Is it that the "Do something else" message is getting displayed or that it is never displayed?

    /Jan

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Oct 13, 2011 @ 22:33
    Tom Fulton
    2

    Hey Fuji,

    I think you want to move the <xsl:choose> outside of the for-each, otherwise the code inside the for-each will never be run if there are no child nodes from $source, right?  Or are you actually looking for child nodes of childs of source?

    How about...

    <xsl:variable name="sourceXml" select="umbraco.library:GetXmlNodeById($source)" />

    <xsl:choose>
      <xsl:when test="count($sourceXml/*[@isDoc and string(umbracoNaviHide) != '1']) &gt; 0">
        <xsl:for-each select="$sourceXml/*[@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:value-of select="somevalue"/>                          
        </xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
        Do something else (there are no children)
      </xsl:otherwise>
    </xsl:choose>              

    -Tom

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 13, 2011 @ 22:34
    Fuji Kusaka
    0

    Hey Jan,

    Well i just want to display the Child nodes of the selected source if there is any child and if not then the "Do something else"

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 13, 2011 @ 22:38
    Fuji Kusaka
    0

    Tom this is exactly what i was looking for.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Oct 13, 2011 @ 22:40
    Chriztian Steinmeier
    2

    Hi Fuji,

    Set a variable to hold all the childnodes - do your for-each on that (or apply some templates).

    If the variable is empty, nothing will happen.

    Afterwards, do a simple if and print a message when the set was empty.

    <xsl:variable name="$sourceChildren" select="umbraco.library:GetXmlNodeById($source)/*[@isDoc][not(umbracoNaviHide = 1)]" />
    
    <xsl:for-each select="$sourceChildren">
        <!-- Do stuff with the nodes -->
    </xsl:for-each>
    <xsl:if test="not($sourceChildren)">
        <!-- There's no spider here... -->
    </xsl:if>

    Also: No need to count, and no need to string() anything - like a Mac, "it just works" :-) 

    /Chriztian

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 13, 2011 @ 22:42
    Fuji Kusaka
    0

    I will give this a try as well. Thanks for the help @Tom, @Jan, @Chriztian

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Oct 13, 2011 @ 22:49
    Fuji Kusaka
    0

    Hey Chriztian,

    Works just fine.......thanks for this again.

  • 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