Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    May 06, 2012 @ 18:43
    umbracocool
    0

    Counter or accumulator with XSLT For Each

    Hi, I have been investigated and have not encontardo solution to the problem.

    What I want is to make a counter in a for-each with <xsl:variable> not serve me!, How I can do.?

    The equivalent of what I get is this:

    var a=0;
    for (var i = 0; i <= 99, i + +) {
         a += 1;
        if (a == 10) {
           / / Execute something!
           a = 0;
        }
    }

    Thank you!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 06, 2012 @ 21:12
    Chriztian Steinmeier
    0

    Hi umbracocool,

    This exact behavior is *very rarely* (if ever, really) needed in XSLT - but you may have a legitimate case, so lets hear what it is exactly you need to do - e.g., are you trying to group X number of nodes in separate <div> tags, or are you trying to output a sequence of numbers?

    In XSLT you can't reassign a variable - variables in XSLT are like constants in other languages; Sometimes the solution requires rethinking by grouping elements and at other times it may require recursion - it all depends...

    /Chriztian

  • umbracocool 108 posts 197 karma points
    May 07, 2012 @ 00:37
    umbracocool
    0

    Thank you for answering me! Look at this code, I have this structure, what I do is that when they have 3 nodes can be grouped 3 by 3 by tag

     

    <div class="wrapper">

    <div class="pages">

    <a href="#">Item1</a>

    <a href="#">Item2</a>

    <a href="#">Item3</a>

    </div>

    <div class="pages">

    <a href="#">Item4</a>

    <a href="#">Item5</a>

    <a href="#">Item6</a>

    </div>

    <div class="pages">

    <a href="#">Item7</a>

    <a href="#">Item8</a>

    </div>

    </div>

     

    Thank you very much!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 07, 2012 @ 08:36
    Chriztian Steinmeier
    0

    Hi again,

    Alright - check out my answer on this one for a way to do that.

    /Chriztian

  • umbracocool 108 posts 197 karma points
    May 08, 2012 @ 07:11
    umbracocool
    0

    Thank you very much Christian, has served me perfectly!

    <xsl:variablename="news"select="$siteRoot/descendant-or-self::News"/>

    in the select, is "News" a document type or you can use any name you like?

    also

    <xsl:apply-templatesselect="$news/NewsArticle[position() mod 2 = 1]"mode="row"/>
  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 08, 2012 @ 07:56
    Chriztian Steinmeier
    0

    You're welcome :-)

    In case you're asking - News and NewsArticle are the document type's aliases, so you just change them to reflect what yours are called.

    /Chriztian

  • umbracocool 108 posts 197 karma points
    May 08, 2012 @ 17:33
    umbracocool
    0

    Right! Right!, Thank You!

Please Sign in or register to post replies

Write your reply to:

Draft