Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 karma points
    Jan 19, 2012 @ 10:38
    Claushingebjerg
    0

    Grouping nodes in list

    Hi im trying to wrap subpages from an id in pairs of 2, but im kinda stuck.
    So any pointer would be very nice.
    Right now i have the following code, which i read up on somewhere, but i think either my scpoping or matching is off.

    <xsl:variable name="source" select="1056"/>
    <xsl:variable name="n" select="number(2)"/>

    <xsl:template match="/">
      <div id="testimonials">
        <xsl:apply-templates select="umbraco.library:GetXmlNodeById($source)/node [position() mod $n = 1]"/>
    </div>
    </xsl:template>  
      
    <xsl:template match="node">
    <div class="clients-testimonials">
      <xsl:for-each select=". | following-sibling::item[position() &lt; $n]">
        <blockquote>
          Output node values here
        </blockquote 
      </xsl:for-each>
    </div>    
    </xsl:template>        
    </xsl:stylesheet>
  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 11:01
    Rodion Novoselov
    0

    Hi. It can be done e.g. the following way:

      <xsl:for-each select="$node/*[@isDoc][string(umbracoNaviHide) != '1']">
        <xsl:if test="position() mod 2 = 1">
          <xsl:value-of select="'&lt;div&gt;'" disable-output-escaping="yes"/>
        </xsl:if>
        <p>
        <xsl:value-of select="@nodeName"/>
        </p>
        <xsl:if test="position() mod 2 = 0 or position() = last()">
          <xsl:value-of select="'&lt;/div&gt;'" disable-output-escaping="yes"/>
        </xsl:if>
      </xsl:for-each>
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 19, 2012 @ 11:07
    Chriztian Steinmeier
    0

    Hi Claus,

    In your node template you're selecting <item> siblings - probably a typo, right? Try this instead:

    <xsl:variable name="source" select="1056" />
    <xsl:variable name="n" select="2" />
    
    <xsl:template match="/">
        <div id="testimonials">
            <xsl:apply-templates select="umbraco.library:GetXmlNodeById($source)/node[position() mod $n = 1]" />
        </div>
    </xsl:template>  
    
    <xsl:template match="node">
        <div class="clients-testimonials">
            <xsl:for-each select=". | following-sibling::node[position() &lt; $n]">
                <blockquote>
                    Output node values here
                </blockquote> 
            </xsl:for-each>
        </div>
    </xsl:template>
    

    /Chriztian

  • Claushingebjerg 939 posts 2574 karma points
    Jan 19, 2012 @ 11:36
    Claushingebjerg
    0

    Hmmm Chriztian.
    It still doesnt work.It renders the main div "Testemonials" but doesnt render "client-testemonials" at all.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 19, 2012 @ 11:42
    Chriztian Steinmeier
    0

    Hi Claus - works on my machine :-)

    Ok, you're using the old schema, right? (Hence the "node" element)

    /Chriztian

     

  • Claushingebjerg 939 posts 2574 karma points
    Jan 19, 2012 @ 11:43
    Claushingebjerg
    0

    no, im on 4.7.1

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 19, 2012 @ 11:48
    Chriztian Steinmeier
    0

    OK - that explains it - you need to use *[@isDoc] instead of node (or better: If they're all the same Document Type - use the alias, e.g.: Testimonial)

    <xsl:templatematch="/">
                   
    <divid="testimonials">
                   
    <xsl:apply-templatesselect="umbraco.library:GetXmlNodeById($source)/*[@isDoc][position() mod $n = 1]"/>
                   
    </div>
           
    </xsl:template>  

           
    <xsl:templatematch="*[@isDoc]">
                   
    <divclass="clients-testimonials">
                           
    <xsl:for-eachselect=". | following-sibling::*[@isDoc][position() &lt; $n]">
                                   
    <blockquote>
                                           
    <xsl:value-ofselect="@nodeName"/>
                                   
    </blockquote>
                           
    </xsl:for-each>
                   
    </div>
           
    </xsl:template>

    /Chriztian

    EDIT: Updated to use GetXmlNodeById()

  • Claushingebjerg 939 posts 2574 karma points
    Jan 19, 2012 @ 12:52
    Claushingebjerg
    0

    im going crazy!

    Ive copy/pasted your code, but it still doesnt render the inner div... Ive been staring at it for ages, but cant seem to find any errors! 

    Doing a normal

    <xsl:for-each select="umbraco.library:GetXmlNodeById(1056)/* [@isDoc and string(umbracoNaviHide) != '1']">
          <xsl:value-of select="@nodeName"/>
    </xsl:for-each>

    Works fine, so the nodes are published and accessible...

  • Rodion Novoselov 694 posts 859 karma points
    Jan 19, 2012 @ 12:57
    Rodion Novoselov
    0

    It seems there's a misspelling - "node" means any node with the name "node".

    To select all nodes you need to spell it as "node()".

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 19, 2012 @ 13:00
    Chriztian Steinmeier
    0

    Hi Claus,

    My bad!! Really - I forgot to use GetXmlNodeById() - (on my local machine I use something else that doesn't work in Umbraco context).

    I've updated the code above - please try again.

    @Rodion: "node" in this context is actually from the old XML Schema in Umbraco; Bit confusing, yes, if you're used to XSLT :-)

  • Claushingebjerg 939 posts 2574 karma points
    Jan 19, 2012 @ 13:05
    Claushingebjerg
    0

    SUCCESS!!!! i thought

    //*

    was som kind of fancy shorthand :)

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Jan 19, 2012 @ 13:12
    Chriztian Steinmeier
    0

    It's a very bad shorthand - but works fine when you've only got a small set of nodes for testing :-)

    /Chriztian

  • abhijeetwaychal 5 posts 25 karma points
    Dec 02, 2012 @ 14:40
    abhijeetwaychal
    0

    Thanks Chriztian and Claus

    Updatd XSLT worked at it is with modifcation //*

     



Please Sign in or register to post replies

Write your reply to:

Draft