Copied to clipboard

Flag this post as spam?

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


  • praveity 100 posts 125 karma points
    May 18, 2011 @ 10:35
    praveity
    0

    group 3 items as one set for div in <for:each/>

    Hi to all,

    I have a parent node which have 6 child nodes. Now I want to loop through all these nodes, but grouping them in different divs with a chunk of 3 nodes each.

    parent node

    -- child 1

    -- child 2

    -- child 3

    -- child 4

    -- child 5

    -- child 6

    like:

    <div class="group1">

    <div>child1 </div>

    <div>child2 </div>

    <div>child3 </div>

    </div>

    <div class="group2">

    <div>child4 </div>

    <div>child5 </div>

    <div>child6 </div>

    </div>

  • Rich Green 2246 posts 4008 karma points
    May 18, 2011 @ 11:10
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 18, 2011 @ 11:37
  • praveity 100 posts 125 karma points
    May 18, 2011 @ 11:39
    praveity
    0

    Hi Rich,

    I want chunks of first 3 child nodes to be in one div and then another 3 child nodes on another div.

    The examples shown list the even positioned node to one group and odd-positioned to another.

    I want nodes positioned 1,2,3 on one div and nodes positioned 4,5,6 on another div.

     

      <xsl:template match="/">
        <!-- start writing XSLT -->
        <xsl:for-each select="$currentPage/CB_Page[@isDoc] | $currentPage/CB_NewsGroup[@isDoc]">
          <xsl:variable name="pos" select="position()"/>
          <xsl:if test="$pos &lt;= 3">
            <div class="holder">
              <xsl:call-template name="renderContent">
              </xsl:call-template>
            </div>
          </xsl:if>
          <xsl:if test="$pos &gt;3 and $pos &lt;=6">
            <div class="holder">
              <xsl:call-template name="renderContent">
              </xsl:call-template>
            </div>
          </xsl:if>
          <xsl:if test="$pos &gt; 7">
            <div class="holder">
              <xsl:call-template name="renderContent">
              </xsl:call-template>
            </div>
          </xsl:if>
        </xsl:for-each>
      </xsl:template>

    I just want class holder to be repeated only once for the child nodes 1,2,3.

    Then repeat it again for chlid nodes 4,5,6 and so on.

Please Sign in or register to post replies

Write your reply to:

Draft