Copied to clipboard

Flag this post as spam?

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


  • Matias 27 posts 68 karma points
    Mar 13, 2013 @ 09:45
    Matias
    0

    Div inside div for every 4 chiild

    Hallo everyone,

     

    I hope someone can help me with this problem. I have a page where I want to have a div, and inside that div another div which is suppose to run 4 times, like this:

    <div1>
        <div2> something </div2>
        <div2> something </div2>
        <div2> something </div2>
        <div2> something </div2>
    </div1>
    <div1>
        .....

    I have got this so far, but no idea how to finish it off:

    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
            <div class="product_oversight">
                <xsl:if test="position() &lt;= 4">
                            <div class="product_brief">
                                    <img>
                                        <xsl:attribute name="src"> 
                                            <xsl:value-of select="oversigtsbilled" /> 
                                        </xsl:attribute> 
                                    </img>
                                        <p class="product_title"><xsl:value-of select="oversigtTitle" /></p>
                                        <p><xsl:value-of select="oversigtTeaser"/></p>
    
                                        <a href="{umbraco.library:NiceUrl(@id)}">Læs mere</a>
                            </div>
                </xsl:if>
            </div>
        </xsl:for-each>

    I am well aware that this is only running 4 times, but I have no idea how to get the last part to work.

    Help pls! Thanks in advance.

  • Rich Green 2246 posts 4008 karma points
    Mar 13, 2013 @ 10:06
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 13, 2013 @ 10:09
    Dennis Aaen
    0

    Hi Matias,

    I search the forum for similar posts on the subject.

    And I think you can find inspiration or use Chriztian Steinmeier answers.Chriztian is really good at XSLT.

    http://our.umbraco.org/forum/developers/xslt/11527-Problem-with-listing-HTLM-strcuture-with-XSLT

    Hope it can help you out.

    /Dennis

  • Matias 27 posts 68 karma points
    Mar 13, 2013 @ 10:46
    Matias
    0

    Hallo both of you,

    Thanks for your answer, I did find this solution when searching. However I do not understand it totally. I have tryed to change something, but nothing seems to chance on my page. It seems like my situation is a bit different, which may be why I do not understand it.

    I have a overview-page, which has x number of children. This overview-page have to get some properties from these childs. Is that how this code works too?

  • Rich Green 2246 posts 4008 karma points
    Mar 13, 2013 @ 10:48
    Rich Green
    0

    Hey Matias,

    You have to let us know which bit you're having problems with.

    The solution we posted a link to show's you how to determine when to open / close DIV's so you can have every 4th one closed.

    Listing the children is a different question.

    However to answer your question, the answers we linked to are generic.

    Rich

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 13, 2013 @ 11:06
    Chriztian Steinmeier
    0

    Hi Matias,

    I think you need to show us the actual output you want, e.g., is it something like this: ?

    <div class="product_oversight">
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
    </div>
    <div class="product_oversight">
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
        <div class="product_brief">...</div>
    </div>
    
    - where each product_brief is a child of $currentPage?

    /Chriztian

  • Matias 27 posts 68 karma points
    Mar 13, 2013 @ 11:22
    Matias
    0

    The basis problem is I not understand everything, basicly what is going on on every step. I have only worked with umbraca for 3 weeks now, and this kode snippet is a bit advance for me to understand. This gives me a problem with replacing the right context with my stuff.

    eg. this bit:

    !-- Grab the data to output -->
            <xsl:variable name="nodes">
                    <xsl:copy-of select="$root//*[@nodeType = 1074][not(umbracoNaviHide = 1)]" />
            </xsl:variable>

    Does this mean that at the nodeID (Is nodetype = nodeID?) the result are places in a variable?

    This I have no idea what does / what it is suppose to achieve?

    <!-- Enable XPath selection in nodes -->
            <xsl:variable name="data" select="make:node-set($nodes)" />

    Then there are 3 parts which is worked around the "apply-template" coding, which I have never work with. I read some stuff about if, but is in generel not sure how it works.

    <xsl:template match="/">
                    <!-- Apply templates to every third document, starting with the first  -->
                    <xsl:apply-templates select="$data/*[position() mod 3 = 1]" mode="row" />
            </xsl:template>
    
            <!-- Template to start a row -->
            <xsl:template match="*[@nodeType = 1074]" mode="row">
                    <div class="row">
                            <!-- Now render this document and the following 2 -->
                            <xsl:apply-templates select=". | following-sibling::*[@nodeType = 1074][position() &lt; 3]" mode="col" />
                    </div>
            </xsl:template>
    
            <!-- Template for a column -->
            <xsl:template match="*[@nodeType = 1074]" mode="col">
                    <div class="col">
                            <!-- Redefine class for every third item -->
                            <xsl:if test="position() mod 3 = 0">
                                    <xsl:attribute name="class">col last</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="@nodeName" />
                    </div>
            </xsl:template>
  • Matias 27 posts 68 karma points
    Mar 13, 2013 @ 11:28
    Matias
    0

    Hi Christian,

    My Content section looks like this:

    product
        Artikel1
        Artikel2
        ...

    Inside each artikel, there are some parameter which I would like to take out and use in the template for product.

    You are right my ending html is suppose to look like this.

    <divclass="product_oversight">
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
    </div>
    <divclass="product_oversight">
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
           
    <divclass="product_brief">...</div>
    </div>

    Inside each <div class="product_brief">

    <img>
    <xsl:attribute name="src"> 
        <xsl:value-of select="oversigtsbilled" /> 
        </xsl:attribute> 
    </img>
    <p class="product_title"><xsl:value-of select="oversigtTitle" /></p>
    <p><xsl:value-of select="oversigtTeaser"/></p>
    
    <a href="{umbraco.library:NiceUrl(@id)}">Læs mere</a>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 8x admin c-trib
    Mar 13, 2013 @ 15:55
    Chriztian Steinmeier
    100

    Hi Matias,

    Here's something that should work as a sample for you - feel free to ask about the specifics of this one:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:umbraco.library="urn:umbraco.library"
            exclude-result-prefixes="umbraco.library"
    >
    
            <xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
    
            <xsl:param name="currentPage" />
            <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
    
        <!--
            Grab all the nodes you need to render - you can do this in many ways,
            this assumes they are all of the document type Artikel and that they are
            children of currentPage:
        -->
            <xsl:variable name="nodes" select="$currentPage/Artikel[not(umbracoNaviHide = 1)]" />
    
            <!-- How many should be grouped together? -->
            <xsl:variable name="groupSize" select="4" />
    
            <xsl:template match="/">
                    <!-- Apply templates to all the "first" Artikel nodes in each group in "wrapper" mode -->
                    <xsl:apply-templates select="$nodes[position() mod $groupSize = 1]" mode="wrapper" />
            </xsl:template>
    
            <!-- Template to start a group -->
            <xsl:template match="Artikel" mode="wrapper">
                    <div class="product_oversight">
                            <!-- Now process this Artikel and the following in the same group, in "item" mode -->
                            <xsl:apply-templates select=". | following-sibling::Artikel[position() &lt; $groupSize]" mode="item" />
                    </div>
            </xsl:template>
    
            <!-- The actual rendering template for an Artikel -->
            <xsl:template match="Artikel" mode="item">
                    <div class="product_brief">
                        <img src="{oversigtsbilled}" />
                        <p class="product_title"><xsl:value-of select="oversigtTitle" /></p>
                        <p><xsl:value-of select="oversigtTeaser"/></p>
                        <a href="{umbraco.library:NiceUrl(@id)}">Læs mere</a>
                    </div>
            </xsl:template>
    
    </xsl:stylesheet>

    /Chriztian

  • Matias 27 posts 68 karma points
    Mar 17, 2013 @ 18:53
    Matias
    0

    Thanks Chriztian!

    It works like a charm and I think I understood most of it too. Very nice comment and understanding code!

     

Please Sign in or register to post replies

Write your reply to:

Draft