Copied to clipboard

Flag this post as spam?

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


  • Stefan 117 posts 215 karma points
    Jul 17, 2009 @ 20:07
    Stefan
    0

    Help with correct XPath

    Hi.

    I have a small newslist in my master template, that shows the names of the number of news-articles specified from a textfield ("nyhedsgruppeItems") from a document type called "Nyhedsgruppe".

    It's working when I'm on the "Nyhedsgruppe" page (all news-nodes are childs of "Nyhedsgruppe"), but regardless of which other page I navigate to, it stops working. I can't figure out how to write the correct XPath to get it working.

    Now I have:

    <xsl:variable name="NumberofItemsToDisplay" select="$currentPage/data [@alias = 'nyhedsgruppeItems']" />

     

    nyhedsgruppeItems is an integer telling how many news-articles to display in the newslist.
    Just like this:

     

    <xsl:if test="position()&lt;= $NumberofItemsToDisplay"> <li> <a title="{@nodeName}" href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(@nodeName), $MaxNoChars, '...')" /> </a> </li> </xsl:if>

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Jul 17, 2009 @ 20:28
    Sebastiaan Janssen
    1

    You are trying to get the news items from the currentPage, but they're not there, so you have to go find them higher up in the tree, like so:

    <xsl:for-each select="$currentPage/ancestor-or-self::node //node[@nodeTypeAlias = 'nyhedsgruppeItems']">

  • Ron Brouwer 273 posts 768 karma points
    Jul 17, 2009 @ 20:33
    Ron Brouwer
    0

    Hi Stefan,

    How looks your xsl:foreach or apply-template?
    I think the problem lies in the select.

    Ron

  • Stefan 117 posts 215 karma points
    Jul 17, 2009 @ 20:44
    Stefan
    0

    Sebastiaan,

    Thanks for pointing me in the right direction. Your solution was not quite what I wanted, but your XPath got me going.

    Now I have this variable:

    <xsl:variable name="NumberofItemsToDisplay" select="$currentPage/ancestor-or-self::node //node[@nodeTypeAlias = 'Nyhedsgruppe']/data [@alias = 'nyhedsgruppeItems' ] " />

    That I can call further down my code to get the correct number of items showing from all pages:

    <xsl:if test="position()&lt;= $NumberofItemsToDisplay">

    Thanks for your quick replies!

  • 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