Copied to clipboard

Flag this post as spam?

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


  • Fourfinger 24 posts 44 karma points
    Feb 24, 2012 @ 09:42
    Fourfinger
    0

    Nest for each to scan all nodes

    Hello,

     

    I'm trying to build a script for Umbracon my internship. The point of the script is the following.

    I'd like to execute it from any node, make it scan from the root down, and look for a node named "Slider" which is of type Textpage, and when he found that one, he should scan that node only, and get all the children (which will be of the doc type "Slide"), so I can put a slider anywhere, and he'd still be able to just create a folder named "Slider" to contain the slides needed as childnodes.

     

    What I have so far:

     

      <!--Scan from current page-->
      <xsl:for-each select="$currentPage/*">
        <!-- If the nodename is "Slider", i need to list all your child nodes -->
        <xsl:if test="@nodeName = 'Slider'">
          <!-- Print the name for debug (should be "Slider")-->
          <xsl:value-of select="@nodeName"/><br/>
            <!-- I'd like to give the node "slider" as input for the nested for each loop-->
            <xsl:for-each select="@id/*">
              <xsl:value-of select="@nodeName"/><br/>
            </xsl:for-each>
        </xsl:if>
      </xsl:for-each>

     

     

     

    Any help would be greatly appreciated! Thanks in advance!

  • Fourfinger 24 posts 44 karma points
    Feb 24, 2012 @ 09:47
    Fourfinger
    0

    Okay, I've got something more like it! I'm getting the hang of this.. I guess.

     So, when I run the XSLT from the "Home" node, it does what I want it to do. Now I should get it to run from any node any where, but still start from the root node.

    Thanks!

    What i've got now:


     
      <xsl:for-each select="$currentPage/*">
        
        <xsl:if test="@nodeName = 'Slider'">
          
          <xsl:value-of select="@nodeName"/><br/>
           
            <xsl:for-each select="./*">
              <xsl:value-of select="@nodeName"/><br/>
            xsl:for-each>
        xsl:if>
      xsl:for-each>
  • Fourfinger 24 posts 44 karma points
    Feb 24, 2012 @ 10:54
    Fourfinger
    0

    I've found the solution!

    Create a variable in the beginning of the script like this:
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />

     

    And then you can for example start your for each like this:

    <xsl:for-each select="$siteRoot//* [@isDoc and string(umbracoNaviHide) != '1']">


    Thanks anyway! :)

     

Please Sign in or register to post replies

Write your reply to:

Draft