Copied to clipboard

Flag this post as spam?

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


  • Kate 267 posts 610 karma points
    Aug 07, 2013 @ 14:39
    Kate
    0

    making a loop

    Hi

    In my xslt file I have some plain html that looks like this:
    <li class="" style="background:url(images/prop1.gif)  no-repeat;">Text content</li>
    <li class="" style="background:url(images/prop2.gif)  no-repeat;">Lorem Ipsum</li>
    <li class="" style="background:url(images/prop3.gif)  no-repeat;">Lorem Ipsum</li>
    <li class="" style="background:url(images/prop4.gif)  no-repeat;">Lorem Ipsum</li>

    Now my question is can i loop through each <li> using
    <xsl:for-each
    select="....">
        ...
    </xsl:for-each>

    I need to change the background-images and text in each <li> from Content. The code I got so fare for this is like below, but I dont know how to make the loop.
    I know that it always has to loop through the list 4 times.

    <xsl:if test="./ikon1!=''">
    <xsl:variable name="medialist1" select="umbraco.library:GetMedia(./ikon1, 0)" />
    <xsl:if test="$medialist1">
    <xsl:variable name="url" select="$medialist1/umbracoFile" />
    <li class="" style="background:url({$url}) no-repeat;"><xsl:value-of select="tekstTilListeEmne1" /></li>
    </xsl:if>
    </xsl:if>

    Hope it makes sense

    /Kate

     

     

  • Kate 267 posts 610 karma points
    Aug 08, 2013 @ 11:27
    Kate
    0

    Is it possible to make anything like this in umbraco/xslt file?

    <?php
    for ($i=1; $i<=5; $i++) 
    {
      echo "The number is " . $i . "<br>"; 
    }
    ?>
  • andrew shearer 409 posts 517 karma points
    Aug 17, 2013 @ 04:38
    andrew shearer
    0

    what version of Umbraco are you using, and is there a chance of using razor instead of xslt? Your required loop would be trivial to write then.

     

  • Dennis Aaen 4457 posts 17970 karma points admin hq c-trib
    Aug 17, 2013 @ 11:19
    Dennis Aaen
    0

    Hi Kate,

    <xsl:if test="./ikon1!=''">
        <ul>
            <xsl:for-each select="./YourDocumentTypeAlias">
                <xsl:if test="./ikon1!=''">
                    <xsl:variable name="medialist1" select="umbraco.library:GetMedia(./ikon1, 0)" />
                    <xsl:if test="$medialist1">
                        <xsl:variable name="url" select="$medialist1/umbracoFile" />
                        <li class="" style="background:url({$url}) no-repeat;">
                            <xsl:value-of select="tekstTilListeEmne1"  />
                        </li>
                    </xsl:if>
                </xsl:if>
            </xsl:for-each>
        </ul>
    </xsl:if>

    With this code you should loop through all the nodes with a specific document type.

    Hope this can help you.

    /Dennis

  • Kate 267 posts 610 karma points
    Aug 17, 2013 @ 14:06
    Kate
    0

    Hi Dennis

    it's not quite what I need.
    I need it to count 1 up each time it runs through the loop so that ikon1 become ikon2, ikon3...

    I think I have to take a look at the razor thing :-)

     

    Andrew - the umbraco is version 4.11.10 and I have now ideen on how to use razor. Can you give me a hint on were to start?

    /Kate

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Aug 18, 2013 @ 20:36
    Chriztian Steinmeier
    0

    Hi Kate,

    In XSLT you practically never need to just count from 1 to X to do something; You're pretty much always doing something to a chunk of data, which is exactly what you have here too; You have four pieces of content that happen to be named ikon1, ikon2 etc.

    XSLT works with by creating templates for content, so all you have to do is create a template with the desired output and then make sure to use that template for all four fields, e.g.:

    <!-- Process all ikon# properties -->
    <xsl:apply-templates select="$currentPage/*[starts-with(name(), 'ikon')]" />
    
    <!-- Template for ikon# output -->
    <xsl:template match="*[starts-with(name(), 'ikon')]">
        <xsl:if test="normalize-space()">
            <xsl:variable name="myIndex" select="substring-after(name(), 'ikon')" />
            <xsl:variable name="medialist" select="umbraco.library:GetMedia(., 0)" />
            <xsl:if test="not($medialist[error])">
                <li style="background:url({$medialist/umbracoFile}) no-repeat;">
                    <xsl:value-of select="../*[name() = concat('tekstTilListeEmne', $myIndex)]" />
                </li>
            </xsl:if>
        </xsl:if>
    </xsl:template>
    

    No need to do any counting for that :-)

    (If you want to, you can use <xsl:template match="ikon1 | ikon2 | ikon3 | ikon4"> instead of the substring thing - same with the select of the <xsl:apply-templates />)

    /Chriztian

  • Kate 267 posts 610 karma points
    Aug 19, 2013 @ 08:40
    Kate
    0

    Thanks Chriztian.

    I will try that :-)

  • 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