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)
<!-- wrap project title with link --> <aclass="downloadLink"href="{$ecmLink}"> <divclass="projectTitle"> <xsl:value-ofselect="@nodeName"/> <!-- small attachment icon --> <divclass="downloadIcon"><imgsrc="/images/icons/download.png"/></div> </div> </a>
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.
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.
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 " "> ]>
<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>
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 :-)
Hope this helps,
/Dennis
Hi Dennis,
Thanks for trying but that returns NULL and hides every heading.
Hi Devin,
You just need to only iterate the groups that have children, so try changing the for-each to this:
/Chriztian
As the rep says... "You rock!" +1
I knew it would be something simple but just couldn't get it!
Thanks mate.
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.
Hi Devin,
Yes - of course:
(The normalize-space() function removes all whitespace, so an accidental space or tab character doesn't count as content)
/Chriztian
Hi Devin,
I think that you can do the check with something like this.
Then it will only output this markup if the link is not empty
Hope this helps, and works.
/Dennis
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.
is working on a reply...