Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    Apr 25, 2016 @ 19:25
    Connie DeCinko
    0

    Most recent content node where value is not empty

    Hoping someone can give my brain a jumpstart today.

    Via XSLT, how do I get the node ID of a content item, where a property (photo) is not empty... sort the results by a date property and get the one, most recent node?

  • Connie DeCinko 931 posts 1160 karma points
    Apr 25, 2016 @ 19:49
    Connie DeCinko
    0

    This looks like it might work but I'm not getting anything.

    <xsl:for-each select="$currentPage/descendant::* [@isDoc and string(photo)!=''][1]">
        <xsl:sort select="publicationDate" order="descending" />
        <xsl:variable name="article" select="@id" />
    </xsl:for-each>
    
  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Apr 25, 2016 @ 20:29
    Chriztian Steinmeier
    0

    Hi Connie,

    You need to do the position-test inside the loop (essentially after the sorting) and not when selecting the nodes to iterate (your for-each only iterates the first item), e.g.:

    <xsl:for-each select="$currentPage//*[@isDoc][normalize-space(photo)]">
        <xsl:sort select="publicationDate" data-type="text" order="descending" />
        <xsl:if test="position() = 1">
            <!-- Do something with the current node here -->
        </xsl:if>
    </xsl:for-each>
    

    I'm guessing you need the ID to do the rendering - but just so you know: You can do the rendering inside the for-each if you want, because you've already got a reference to it, e.g.:

    <xsl:for-each select="$currentPage//*[@isDoc][normalize-space(photo)]">
        <xsl:sort select="publicationDate" data-type="text" order="descending" />
        <xsl:if test="position() = 1">
            <section class="latest">
                <h1><xsl:value-of select="(@nodeName[not(normalize-space(../header))] | header)[1]" /></h1>
    
                <!-- etc. -->
            </section>
        </xsl:if>
    </xsl:for-each>
    

    Hope that helps,

    /Chriztian

  • Connie DeCinko 931 posts 1160 karma points
    Apr 25, 2016 @ 21:55
    Connie DeCinko
    0

    Yeah, ended up with a bunch of nested loops but, hey it works. Not too bad since it's just hitting that one XML file.

  • 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.

Please Sign in or register to post replies