I have got some xslt that pulls "featuredImages" property from the "NewsArticle" doctype and puts them in a slideshow. I am having some problems getting them to sort by the property "publicationDate" as I keep ending up with duplicate niceURL's for the "NewsArticle"'s. I am sure it's the placment of my <xsl:for-each>, but I can't find the right location for it. Any help would be apppreciated. Thanks.
Sorting News Articles by Publication Date
Hello,
I have got some xslt that pulls "featuredImages" property from the "NewsArticle" doctype and puts them in a slideshow. I am having some problems getting them to sort by the property "publicationDate" as I keep ending up with duplicate niceURL's for the "NewsArticle"'s. I am sure it's the placment of my <xsl:for-each>, but I can't find the right location for it. Any help would be apppreciated. Thanks.
<xsl:param name="currentPage"/>
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level=1]"/>
<xsl:template match="/">
<xsl:variable name="articleNode" select="$siteRoot/NewsHome/NewsCategory[3]/DateFolder" />
<xsl:if test="count($articleNode/NewsArticle[featureThisArticle = 1]) > 0">
<div class="block-gallery">
<ul class="galery">
<xsl:apply-templates select="$articleNode" />
</ul>
<div class="slider">
<a class="prev" href="#">prev</a>
<div class="switcher"> </div>
<a class="next" href="#">next</a>
</div>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="NewsArticle">
<xsl:variable name="sortedArticles" select="$siteRoot/NewsHome/NewsCategory[3]/DateFolder/NewsArticle[featureThisArticle = 1]" />
<xsl:for-each select="$sortedArticles">
<xsl:sort select="publicationDate" order="descending" />
<xsl:if test="normalize-space(featuredImage)">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia(featuredImage, 0)/umbracoFile"/>
<li>
<div class="fade"> </div>
<img src="/ImageGen.ashx?image={umbraco.library:GetMedia(featuredImage, 'false')/umbracoFile}&height=325" />
<div class="block-galery">
<img class="grey-seal" src="/media/831667/grey-seal.png"/>
<div class="text-area">
<div class="text">
<strong><xsl:value-of select="headline" /></strong>
<span><xsl:value-of select="teaser" /></span>
<xsl:if test="$currentPage/ancestor-or-self::*/@id > 0">
<a class="read-story" href="{umbraco.library:NiceUrl(./@id)}">FULL STORY</a>
</xsl:if>
</div>
</div>
</div>
</li>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Why doesn't this approach work? I am sorting in the middle of the "apply-templates".
<xsl:param name="currentPage"/>
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level=1]"/>
<xsl:template match="/">
<xsl:variable name="articleNode" select="$siteRoot/NewsHome/NewsCategory[3]/DateFolder" />
<xsl:if test="count($articleNode/NewsArticle[featureThisArticle = 1]) > 0">
<div class="block-gallery">
<ul class="galery">
<xsl:apply-templates select="$articleNode" />
<xsl:sort select="publicationDate" order="descending" />
</xsl:apply-templates>
</ul>
<div class="slider">
<a class="prev" href="#">prev</a>
<div class="switcher"> </div>
<a class="next" href="#">next</a>
</div>
</div>
</xsl:if>
</xsl:template>
<xsl:template match="NewsArticle">
<xsl:if test="normalize-space(featuredImage)">
<xsl:variable name="mediaNode" select="umbraco.library:GetMedia(featuredImage, 0)/umbracoFile"/>
<li>
<div class="fade"> </div>
<img src="/ImageGen.ashx?image={umbraco.library:GetMedia(featuredImage, 'false')/umbracoFile}&height=325" />
<div class="block-galery">
<img class="grey-seal" src="/media/831667/grey-seal.png"/>
<div class="text-area">
<div class="text">
<strong><xsl:value-of select="headline" /></strong>
<span><xsl:value-of select="teaser" /></span>
<xsl:if test="$currentPage/ancestor-or-self::*/@id > 0">
<a class="read-story" href="{umbraco.library:NiceUrl(./@id)}">FULL STORY</a>
</xsl:if>
</div>
</div>
</div>
</li>
</xsl:if>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
got it working with:
<xsl:apply-templates select="$articleNode/NewsArticle">
<xsl:sort select="publicationDate" order="descending" />
</xsl:apply-templates>
Any suggestions on keeping the number of NewsArticles to 12? Even if there are more in the Folder containing them.
Hi Steve,
Great to see you got it "sorted" :-)
To limit the number of articles output, just substitute a for-each for the apply-templates and test the position within:
/Chriztian
Thanks Chriztian! That did the trick. I don't know why I didn't see that. As always, you are a big help.
is working on a reply...