Copied to clipboard

Flag this post as spam?

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


  • jonok 260 posts 476 karma points
    Sep 07, 2010 @ 11:47
    jonok
    0

    4.5 - Get position()=last() that is not empty

    I'm copying some of my old 4.0 xslt files into 4.5 and I have an xslt file that returns the last non-empty value. Basically it checks if the current page has an 'seoDescription' property value, and if not then returns the parent 'seoDescription' property value. But I can't work out how to get [position()=last()] to work in the 4.5 schema. Here is the code I'm trying to convert:

    <meta name='description'>
        <xsl:attribute name="content">
            <xsl:value-of select="$currentPage/ancestor-or-self::node [string(data[@alias='seoDescription'])!=''] [position()=last()] /data [@alias='seoDescription']" />
        </xsl:attribute>
    </meta>
  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 07, 2010 @ 11:57
    Chriztian Steinmeier
    0

    Hi jonok,

    Try something like this:

    <meta name='description'>
        <xsl:attribute name="content">
            <xsl:value-of select="$currentPage/ancestor-or-self::*[seoDescription[normalize-space()]][last()]/seoDescription" />
        </xsl:attribute>
    </meta>

    /Chriztian

  • jonok 260 posts 476 karma points
    Sep 07, 2010 @ 12:51
    jonok
    0

    Hi Chriztian, that doesn't quite seem to work - it's returning the parent property. For example when using the following page structure and when 'about us' is the current page...

    -Home
    --About us

    ...it is returning the 'home' seoDescription instead of the 'about us' seoDescription.

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Sep 07, 2010 @ 13:03
    Chriztian Steinmeier
    0

    Whoops! Pitfall... - replace the [last()] predicate with a [1] and it should take the right one. 

    /Chriztian

  • jonok 260 posts 476 karma points
    Sep 07, 2010 @ 13:14
    jonok
    0

    Perfect - that did the trick. Thanks very much Chriztian.

  • 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