Copied to clipboard

Flag this post as spam?

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


  • Martin 278 posts 662 karma points
    Nov 02, 2011 @ 14:13
    Martin
    0

    Position Problem Inside Macro / Macro Container

    Hi, Im having some issues with applying a css class based on position within a macro.

    I am also using this macro with a macro container.

    My html output is only applying the first position class.

    Any help would be grateful

    Thanks

    Martin

     

    <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
        <xsl:param name="currentPage"/>
        
        <xsl:variable name="title" select="/macro/title"/>
        <xsl:variable name="info" select="/macro/info"/>
        <xsl:variable name="image" select="/macro/image/Image"/>   
        <xsl:variable name="link" select="/macro/link"/>          
        <xsl:template match="/">
      <!-- start writing XSLT -->
        <xsl:if test="$title and $info and $image">
        <div>
    <!-- Apply class on position -->     
                    <xsl:if test="position() = 1">
                            <xsl:attribute name="class">alpha</xsl:attribute>
                    </xsl:if>
                    <xsl:if test="position()  = 2">
                            <xsl:attribute name="class">omega</xsl:attribute>
                    </xsl:if>    
    <!--  link around all -->      
          <xsl:if test="$link">      
          <href="{umbraco.library:NiceUrl($link)}">
    <!-- title and info -->     
            <div class="four columns alpha">     
              <h5><xsl:value-of select="$title"/></h5>          
              <p><xsl:value-of select="$info"/></p>
            </div>  
    <!-- thumbnail image -->
            <div class="two columns omega">  
            <xsl:if test="$image">
              <img src="{$image/umbracoFile}" width="100%" />
            </xsl:if>
            </div>             
          </a>
          </xsl:if>    
        </div>
        </xsl:if>       
        </xsl:template>
  • Martin 278 posts 662 karma points
    Nov 02, 2011 @ 14:23
    Martin
    0

    Ive also tried this approach, but it still output only the "alpha" class

     <xsl:choose>
                <xsl:when test="position() = 1">
                    <xsl:attribute name="class">alpha</xsl:attribute>
                </xsl:when>
                <xsl:when test="position() = last()">
                    <xsl:attribute name="class">omega</xsl:attribute>
                </xsl:when>
            </xsl:choose>

  • Jacob Jensen 40 posts 60 karma points
    Nov 02, 2011 @ 14:25
    Jacob Jensen
    0

    Ur template match="/" is the root node, and there is only a node at position() = 1

    with jquery

    $(".alpha:last").removeClass('alpha').addClass('omega');

    /J

  • Martin 278 posts 662 karma points
    Nov 02, 2011 @ 14:37
    Martin
    0

    Thanks Jacob,

    Im new to xslt & relunctant to use jquery. 

  • Jacob Jensen 40 posts 60 karma points
    Nov 02, 2011 @ 14:39
    Jacob Jensen
    0

    yes, but ur macro only shows one item at the time, so its kinda hard to know when its the last without a parameter more.

    /J

  • Andrei Canef 33 posts 84 karma points
    Nov 05, 2011 @ 21:38
    Andrei Canef
    0

    Hi Martin, 

     

    Could you please give me a bit of details as to what you're trying to achieve? I am a bit confused because, in a macro, you'll only ever have 1 element (the image you're pointing to). As such, the only test case being hit is the one where your position = 1. 

     

  • 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