Copied to clipboard

Flag this post as spam?

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


  • Molly 94 posts 134 karma points
    Apr 16, 2013 @ 15:39
    Molly
    0

    place div after 1st child before 2nd child of a for-each

    Hi 

    I have 8 divs that display an image, title and info in each from what the user has inputted using doc type properties. I have xslt to show them when a new page is added under a certain sector.

    I want to add a 9th div that goes inbetween the first and second divs from above with a logo in so it would looks as follows: 

    1 | logo | 2 

    3 |   4   | 5

    6 |   7   | 8

    on the page, right now i have used parameters to count the 2nd item and add the div with logo in but it is replacing the 2nd item rather than placing between 1 and 2 so right now it's doing this: 

    1 | 2 | 3

    4 | 5 | 6

    7 | 8 | 

    its counting the 2nd as the new logo div which i know about its just i'm not sure how to get it to insert the logo div after the 1st and before the 2nd. Here is a snippet of what i have so far : 

    <xsl:template match="/">

      <xsl:for-each select="$currentPage/squareLanding">

     <xsl:if test="position() &lt;= 9">

                    <xsl:apply-templates select=".">

              <xsl:with-param name="index" select="position()" />   

     </xsl:apply-templates>

     </xsl:if>

     </xsl:for-each>

     </xsl:template>

    <xsl:template match="squareLanding">

    <xsl:param name="index" />

     <div class="view view-tenth">

              <xsl:if test="$index = 2">

     <div class="logoSquare">

     <img src="/images/trans.gif" />

     </div>

              </xsl:if>

     

                  <img>...

     

    Any guide would be great! Thanks 

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 16, 2013 @ 15:56
    Chriztian Steinmeier
    100

    Hi Molly,

    Something like this should do it:

    <xsl:template match="/">
        <xsl:apply-templates select="$currentPage/squareLanding[position() &lt; 9]" />
    </xsl:template>
    
    <xsl:template match="squareLanding">
        <div class="view view-tenth">
            <!-- do standard output for square -->
        </div>
        <xsl:if test="position() = 2">
            <div class="logoSquare">
                <img src="/images/trans.gif" />
              </div>
        </xsl:if>
    </xsl:template>
    

    /Chriztian

  • Molly 94 posts 134 karma points
    Apr 16, 2013 @ 16:19
    Molly
    0

    Thank you Chriztian that's how i need it, it puts it as a 3rd position and not 2nd so it looks like this: 

    1 | 2 | logo 

    3 | 4 | 5

    6 | 7 | 8 

    if i change test="position() = 2">

    to

    test="position() = 1"

    or

    test="position() = 3"

    It displays as follows : 

    1 |  logo

    2 | 3 | 4

    5 | 6 | 7

    8

    Thank you for getting back so quick :) :)  

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 16, 2013 @ 16:25
    Chriztian Steinmeier
    0

    Hi again,

    My mistake - should have been added *before* the normal output of course :-)

    Changing to test for position() = 1 would be the easiest fix, though...

    But are you saying that using either of 1 and 3 gives the same (wrong) output?

    I'm assuming you have some CSS styling doing the column stuff...

    /Chriztian 

  • Molly 94 posts 134 karma points
    Apr 16, 2013 @ 16:34
    Molly
    0

    My bad Chriztian! I stupidly forgot to put a width back on the div and float it left! everything works perfects with position()=1 

    Thank you very much! Looking at the code is much more simpler than the way i was going with it which is always good! 

     

  • 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