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.
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()<= $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>
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']">
Hi Stefan,
How looks your xsl:foreach or apply-template?
I think the problem lies in the select.
Ron
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()<= $NumberofItemsToDisplay">
Thanks for your quick replies!
is working on a reply...