Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    Nov 28, 2011 @ 14:08
    trfletch
    0

    Get last edited node of a certain document type

    Hi All,

    I have an Umbraco 4.7.1 website using the latest XSLT schema. I have installed the nForum package and I am trying to get the latest edited node that is of either one of two document types. I have the following XSLT:

    <xsl:for-each select="descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:sort select="@updateDate" order="descending"/>
    <xsl:if test="self::ForumSection or self::ForumPost ">
    <xsl:value-of select="@nodeName"/>
    </xsl:if>
    </xsl:for-each>

    This of course lists out all the nodes that are of document type ForumSection or ForumPost. I tried adding the following to only get one result but it then showed no results:

    <xsl:for-each select="descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="@updateDate" order="descending"/>
            <xsl:if test="self::ForumSection or self::ForumPost ">
                <xsl:if test="position() = 1">
                    <xsl:value-of select="@nodeName"/>
                </xsl:if>
            </xsl:if>
    </xsl:for-each>

    I then tried the following but this again gave me no results:

    <xsl:for-each select="descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="@updateDate" order="descending"/>
            <xsl:if test="position() = 1">
                <xsl:if test="self::ForumSection or self::ForumPost ">         
                    <xsl:value-of select="@nodeName"/>
                </xsl:if>
            </xsl:if>
    </xsl:for-each>

    So I finally tried the following code but this just listed out all the results again like my first piece of code:

    <xsl:for-each select="descendant::* [@isDoc and string(umbracoNaviHide) != '1']">
        <xsl:sort select="@updateDate" order="descending"/>
         <xsl:if test="position() = 1" and self::ForumSection or self::ForumPost >
                <xsl:value-of select="@nodeName"/>
        </xsl:if>
    </xsl:for-each>

    Can someone please point me in the right direction as to what I can do to just get one result?

    Cheers

    Tony

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 28, 2011 @ 17:23
    Chriztian Steinmeier
    0

    Hi Tony,

    The reason position() isn't working for you is that it works on the "current nodeset" which, in a for-each statement, is the nodes returned from the XPath in the select attribute. If you include the name tests in the selection, it'll work:

    <xsl:for-each select="descendant-or-self::*[self::ForumSection or self::ForumPost][not(umbracoNaviHide = 1)]">
        <xsl:sort select="@createDate" order="descending" />
        <xsl:if test="position() = 1">
            <xsl:value-of select="@nodeName" />
        </xsl:if>
    </xsl:for-each>

    Note also that you don't really need the [@isDoc] predicate when testing for specific Documents, unless you created properties with those names (which Umbraco tries hard to prevent you from by Pascal-casing those...) 

    /Chriztian

  • trfletch 598 posts 604 karma points
    Nov 28, 2011 @ 17:27
    trfletch
    0

    Thanks Chriztian,

    It actually turned out that I didn't need this anymore (I was able to get the info I wanted another way), I did try and delete the post but thanks anyway because I am sure to need something like this in the future so it is good to know the correct way to do it.

    Regards
    Tony

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Nov 28, 2011 @ 21:33
    Chriztian Steinmeier
    0

    Great to hear Tony.

    You shouldn't try to delete the post anyway - this post has a very descriptive title and an answer that's easy to understand - perfect for anyone having that same problem tomorrow or next week.

    /Chriztian

Please Sign in or register to post replies

Write your reply to:

Draft