Copied to clipboard

Flag this post as spam?

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


  • Devin 87 posts 251 karma points
    May 26, 2015 @ 14:27
    Devin
    0

    Don't show if empty

    I have a page which displays project items like so:

    http://prntscr.com/79k8od

    There are two problems I'm facing.

    1. If a project group has no children, it shouldn't show the title for that group (the h2 right after the loop).
    2. After there's an empty group, the row is wrapping everything else like so: (I guess this might be fixed if the title doesn't show for an empty group)

    http://prntscr.com/79ka5h

    Here's the folder structure:

    http://prntscr.com/79kcsb (The folders alias is ProjectsGroup)

    And the current code:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">
       
       
    <xsl:output method="xml" omit-xml-declaration="yes"/>
       
       
    <xsl:param name="currentPage"/>
       
       
    <xsl:variable name="projectGroup" select="$currentPage/ProjectsGroup[@isDoc]"/>
       
       
    <xsl:template match="/">    
           
           
    <xsl:for-each select="$projectGroup">
               
               
    <h2><xsl:value-of select="@nodeName"/></h2>
               
               
    <div class="row">
                   
    <xsl:apply-templates select="*" mode="projectItem"/>
               
    </div>    
               
           
    </xsl:for-each>
           
       
    </xsl:template>
       
       
    <xsl:template match="*" mode="projectItem">
           
           
    <xsl:variable name="status" select="status"/>
           
    <xsl:variable name="ecmLink" select="ecmLink"/>
           
           
    <div class="grid_3">
               
               
    <div class="projectBox">
                   
                   
    <!-- wrap project title with link -->
                   
    <a class="downloadLink" href="{$ecmLink}">
                       
    <div class="projectTitle">
                           
    <xsl:value-of select="@nodeName"/>
                           
    <!-- small attachment icon -->
                           
    <div class="downloadIcon"><img src="/images/icons/download.png" /></div>
                       
    </div>
                   
    </a>
                   
                   
    <p class="projectDescription"><xsl:value-of select="description"/></p>
                   
                   
    <!-- show status bar (red/green) -->
                   
    <xsl:choose>
                       
    <xsl:when test="$status = 'Red'">
                           
    <div class="status red"><xsl:value-of select="normalize-space('')"/></div>
                       
    </xsl:when>
                       
    <xsl:when test="$status = 'Green'">
                           
    <div class="status green"><xsl:value-of select="normalize-space('')"/></div>
                       
    </xsl:when>
                       
    <xsl:otherwise>
                           
                       
    </xsl:otherwise>
                   
    </xsl:choose>                
                   
               
    </div>
           
    </div>
       
    </xsl:template>
       
    </xsl:stylesheet>

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 26, 2015 @ 14:42
    Dennis Aaen
    0

    Hi Devin,

    I think something like this will work for you. I must admit that it´s been a while since I have written XSLT :-)

    <xsl:if test="./child::*[@isDoc] > 0">
         <h2><xsl:value-of select="@nodeName"/></h2>
    </xsl:if>
    

    Hope this helps,

    /Dennis

  • Devin 87 posts 251 karma points
    May 26, 2015 @ 14:54
    Devin
    0

    Hi Dennis,

    Thanks for trying but that returns NULL and hides every heading.

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 26, 2015 @ 15:27
    Chriztian Steinmeier
    100

    Hi Devin,

    You just need to only iterate the groups that have children, so try changing the for-each to this:

    <xsl:for-each select="$projectGroup[*[@isDoc]]">
        <h2><xsl:value-of select="@nodeName"/></h2>
        <div class="row">
            <xsl:apply-templates select="*[@isDoc]" mode="projectItem"/>
        </div>
    </xsl:for-each>
    

    /Chriztian

  • Devin 87 posts 251 karma points
    May 26, 2015 @ 15:31
    Devin
    0

    As the rep says... "You rock!" +1

    I knew it would be something simple but just couldn't get it!

    Thanks mate.

  • Devin 87 posts 251 karma points
    May 29, 2015 @ 12:30
    Devin
    0

    Is there also a way to include a statement to check if the "ecmLink" textstring field is empty in the for-each? I dont' want projects showing up if they don't contain a link.

        <xsl:for-each select="$projectGroup[*[@isDoc]]">
                <h2><xsl:value-of select="@nodeName"/></h2>
                <div class="row">
                    <xsl:apply-templates select="*[@isDoc]" mode="projectItem"/>
                </div>
        </xsl:for-each>
  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    May 29, 2015 @ 12:35
    Chriztian Steinmeier
    1

    Hi Devin,

    Yes - of course:

    <xsl:for-each select="$projectGroup[*[@isDoc][normalize-space(ecmLink)]]">
    

    (The normalize-space() function removes all whitespace, so an accidental space or tab character doesn't count as content)

    /Chriztian

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    May 29, 2015 @ 12:37
    Dennis Aaen
    1

    Hi Devin,

    I think that you can do the check with something like this.

      <!-- wrap project title with link -->
                    <xsl:if test="$ecmLink !=''">
                        <a class="downloadLink" href="{$ecmLink}">
                            <div class="projectTitle">
                                <xsl:value-of select="@nodeName"/>
                                <!-- small attachment icon -->
                                <div class="downloadIcon"><img src="/images/icons/download.png" /></div>
                            </div>
                        </a>
                      <xsl:if>
    

    Then it will only output this markup if the link is not empty

    Hope this helps, and works.

    /Dennis

  • Devin 87 posts 251 karma points
    May 29, 2015 @ 13:58
    Devin
    0

    Thank you both for helping. I did try add the if test != '' check but it didn't work. I guess because as Chriztian said, the white space. Works perfectly though Chrizt thanks a lot.

Please Sign in or register to post replies

Write your reply to:

Draft