Old xslt schema help! List of nodes by date, but with sticky node on top.
Ok, it has been ages since i last asked a question about XSLT, but i am in a situation where i have to edit some files written in the old schema which i have zero clue about.
It is a simple list of latest news posts sorted by date. Now i need to add a new property (true/false) which the editor can tick off wether it should be a sticky or not, and the xslt needs to be edited to reflect this. How do i go about doing this?
Old xslt schema help! List of nodes by date, but with sticky node on top.
Ok, it has been ages since i last asked a question about XSLT, but i am in a situation where i have to edit some files written in the old schema which i have zero clue about.
It is a simple list of latest news posts sorted by date. Now i need to add a new property (true/false) which the editor can tick off wether it should be a sticky or not, and the xslt needs to be edited to reflect this. How do i go about doing this?
Here is the current code:
Hi Frederik,
Here's a way to test for stickiness - assuming it's a boolean property named sticky on the documents being iterated:
<xsl:variable name="absRoot" select="$currentPage/ancestor-or-self::root" /> <xsl:variable name="newsRoot" select="$root//node[@nodeTypeAlias = 'News Area']" /> <xsl:template match="/"> <xsl:for-each select="$newsRoot/node[not(data[@alias = 'umbracoNaviHide'] = 1)]"> <xsl:sort select="@createDate" order="descending" /> <xsl:if test="position() < 11"> <li> <!-- Add sticky class? --> <xsl:if test="data[@alias = 'sticky'] = 1"><xsl:attribute name="class">sticky</xsl:attribute></xsl:if> <h3><a title="{@nodeName}" href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a></h3> <span><xsl:value-of select="data[@alias = 'summary']" /></span> </li> </xsl:if> </xsl:for-each> </xsl:template>/Chriztian
Thank you for the quick reply! But is there a way to get it on top of the list? If its possible with xslt that is.
Oh yes :-)
One smart way would be to make them sort to the top - add this sort before the one for @createDate:
/Chriztian
Ah yes of course! It makes sense now to use sort. I was just confused by the old schema which i havent tried before. Thanks for the help!
is working on a reply...
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.