Copied to clipboard

Flag this post as spam?

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


  • Phil Crowe 192 posts 256 karma points
    Nov 03, 2010 @ 13:10
    Phil Crowe
    0

    check if item in loop is news item

    Am i using the wrong syntax for checking the nodetypealias here? It doesnt seem to work. Always returns 'no' for every item even though i know for a fact some of the are using the news item document type.  

     

    <xsl:for-each select="$currentPage/* [@isDoc]">

                <xsl:choose>

                  <xsl:when test="./@nodeTypeAlias = 'newsItem'">

                   yes

                  </xsl:when>

     

    <xsl:otherwise> no </xsl:otherwise>

    </xsl:choose>

  • Bas Schouten 135 posts 233 karma points
    Nov 03, 2010 @ 13:16
    Bas Schouten
    0

    Hi Phil,

    You have to use "name($currentPage)"

    <xsl:for-each select="$currentPage/* [@isDoc]">

                <xsl:choose>

                  <xsl:when test="name($currentPage) = 'newsItem'">

                   yes

                  </xsl:when>

     

    <xsl:otherwise> no </xsl:otherwise>

    </xsl:choose>

    More info: http://our.umbraco.org/wiki/reference/xslt/45-xml-schema/no-more-@nodetypealias

    Cheers,

    Bas

     

  • Phil Crowe 192 posts 256 karma points
    Nov 03, 2010 @ 13:57
    Phil Crowe
    0

    Hi Bas Ive tried this but the node still says 'no'. so i then tried name(.) at a guess, this didnt work either. If i wanted to exclude a certain document type within my foreach line would it be this:

    <xsl:for-each select="$currentPage/* [@isDoc and name() = 'newsItem']"> ?? this didnt work.

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Nov 03, 2010 @ 14:01
    Chriztian Steinmeier
    0

    Hi Phil,

    Use the self:: axis to test the name when you know it:

    <xsl:for-each select="$currentPage/*[@isDoc]">
        <xsl:choose>
            <xsl:when test="self::newsItem">
                  yes
            </xsl:when>
            <xsl:otherwise> no </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
    

    If you only want to do something to newsItem documents:

    <xsl:for-each select="$currentPage/newsItem">
        <xsl:value-of select="@nodeName" />
    </xsl:for-each>

    /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