I'm struggeling a bit with some xslt code where I need to get all related nodes to the current node and then display them random, but limit the amount of nodes displayed by an integer.
The above returns a set of the correct nodes, but from there I'm quite lost to be honest :( The following code doesn't work as the $spotCount variable returns 1 (I would guess it's because it's counting one set of nodes and not the actual amount of nodes in the set?)
Get related nodes and display them random
Hi all,
I'm struggeling a bit with some xslt code where I need to get all related nodes to the current node and then display them random, but limit the amount of nodes displayed by an integer.
So far, I have this code:
<xsl:variable name="currentPageId" select="$currentPage/@id" />
<xsl:variable name="numSpots" select="umbraco.library:GetXmlNodeById(1177)/antalPartnerSpots" />
<xsl:variable name="spots">
<xsl:for-each select="umbraco.library:GetRelatedNodesAsXml($currentPage/@id)/relations/relation/node">
<xsl:if test="../@typeId = 6">
<xsl:copy-of select="umbraco.library:GetXmlNodeById(@id)" />
</xsl:if>
</xsl:for-each>
</xsl:variable>
The above returns a set of the correct nodes, but from there I'm quite lost to be honest :( The following code doesn't work as the $spotCount variable returns 1 (I would guess it's because it's counting one set of nodes and not the actual amount of nodes in the set?)
<xsl:variable name="spotCount" select="count(msxml:node-set($spots)/node/*)" />
<xsl:value-of select="$spotCount" /><br />
<xsl:choose>
<xsl:when test="$spotCount < $numSpots">
<xsl:variable name="randomNumber" select="floor(Exslt.ExsltMath:random() * $spotCount) + 1"/>
<xsl:variable name="randomItem" select="msxml:node-set($spots)/node [position() = $randomNumber]" />
<xsl:value-of select="$randomItem/@nodeName" />
</xsl:when>
<xsl:otherwise>
<p>No item found</p>
</xsl:otherwise>
</xsl:choose>
Would be great if some of you hardcore xslt-heads out there could shed some light on this ;) Thanks in advance! / Bo
Try something like this:
Alright, thanks to Morten I got this solved and the solutions was:
is working on a reply...