Copied to clipboard

Flag this post as spam?

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


  • Frederik T 234 posts 345 karma points
    Sep 17, 2012 @ 11:38
    Frederik T
    0

    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:


    <xsl:template match="/">

    <xsl:for-each select="umbraco.library:GetXmlAll()//node [@nodeTypeAlias='News Area']/node [string(data [@alias='umbracoNaviHide']) != '1']">

    <xsl:sort select="@createDate" order="descending"/>

    <xsl:if test="position() &lt; 11">
    <li>
    <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 Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 17, 2012 @ 11:50
    Chriztian Steinmeier
    0

    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() &lt; 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

  • Frederik T 234 posts 345 karma points
    Sep 17, 2012 @ 12:13
    Frederik T
    0

    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.

  • Chriztian Steinmeier 2798 posts 8787 karma points MVP 7x admin c-trib
    Sep 17, 2012 @ 12:26
    Chriztian Steinmeier
    0

    Oh yes :-)

    One smart way would be to make them sort to the top - add this sort before the one for @createDate:

    <xsl:sort select="number(boolean(data[@alias = 'sticky'] = 1))" data-type="number" order="descending" />

     

    /Chriztian

     

  • Frederik T 234 posts 345 karma points
    Sep 17, 2012 @ 12:42
    Frederik T
    0

    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!

Please Sign in or register to post replies

Write your reply to:

Draft