Copied to clipboard

Flag this post as spam?

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


  • Inmedia 124 posts 176 karma points
    Sep 22, 2011 @ 09:23
    Inmedia
    0

    Only show div if alias has content... What am I doing wrong?

    Hi Umbracians

    I have a problem using the if-test statement... I have an image slider in one of my templates, which uses the XSLT you see below. The images are created as sub-nodes of the node they should be shown in... And it works fine, until I try to tell the XSLT that it should only show the "imageText" div when the alias "contentPicture" is filled out... The "contentPicture" is an alias on the picture document type.

    I dont know what I am doing wrong here... Can someone please help me out?


    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">

         <li class="squareRandom">
                <div style="background-image: url({picture}); width: 650px; height: 300px; padding: 50px 0 0 30px">

                     <xsl:if test="data [@alias = 'contentPicture'] != ''">
                          <div class="imageText" style="width: 400px; ">
                                <xsl:value-of select="contentPicture" disable-output-escaping="yes"/>
                          </div>
                    </xsl:if>
                </div>
         </li>
      
    </xsl:for-each>

     

     

    Kind regards from Denmark

    // Mikkel Johansen

    Inmedia

  • Lennart Stoop 304 posts 841 karma points
    Sep 22, 2011 @ 09:41
    Lennart Stoop
    0

    Hi Mikkel,

    Since your if block is inside a foreach and you want to refer to the "current" image node, you'll want to use the current() XSLT function:

    <xsl:if test="current()/data [@alias = 'contentPicture'] != ''">

     

    Grtz

    L

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 22, 2011 @ 09:41
    Fuji Kusaka
    0

    Hi Mikkel,

    Am not sure i really understood what you asked but you can try chaning the your test to something like

      <xsl:choose>
         <xsl:when test="data [@alias = 'contentPicture'] !='' ">
                   <div class="imageText" style="width: 400px; ">
                                <xsl:value-of select="contentPicture" disable-output-escaping="yes"/>
                          </div>
         </xsl:when>
    <xsl:otherwise>
    <!--  Remove the DIV  -->
    </xsl:otherwise>
    </xsl:choose>

     

     

     

     

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 22, 2011 @ 10:10
    Chriztian Steinmeier
    0

    Hi Mikkel,

    The test you're performing uses the old XML Schema - you can do it like this:

    <xsl:for-each select="$currentPage/*[@isDoc][not(umbracoNaviHide = 1)]">
        <li class="squareRandom">
            <div style="background-image: url({picture}); width: 650px; height: 300px; padding: 50px 0 0 30px;">
                <xsl:if test="normalize-space(contentPicture)">
                    <div class="imageText" style="width: 400px;">
                        <xsl:value-of select="contentPicture" disable-output-escaping="yes" />
                    </div>
                </xsl:if>
            </div>
        </li>
    </xsl:for-each>
    

     

    /Chriztian

  • 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