And I like to get a random file, not the folder or subfolder. So I created a doctype 'multimedia_file'. Here's the xslt that does not work. I got an error : "Expression must evaluate to a node-set."
Ok, the code Jeff gave me bring the same error, so I tried kipusoep code and it almost works like I want. I changed the last line to have only one result :
<xsl:template match="/"> <!-- SELECT THE DOCUMENT TYPE ALIAS TO SEARCH FOR --> <xsl:variable name="documentTypeAlias" select="'multimedia_file'"/>
<!-- GET ALL NODES OF THE SELECTED DOCUMENT TYPE ALIAS --> <xsl:variable name="allIds"> <xsl:for-each select="$currentPage/ancestor-or-self::node[@level=1]//node[@nodeTypeAlias=$documentTypeAlias]"> <xsl:copy-of select="." /> </xsl:for-each> </xsl:variable>
<!-- COUNT THE NUMBER OF NODES --> <xsl:variable name="numItems" select="count(msxml:node-set($allIds)/node)" />
<!-- NOW THAT YOU HAVE A RANDOM ITEM, YOU CAN DISPLAY IT --> <xsl:value-of select="$randomItem/@nodeName" /> </xsl:when> <xsl:otherwise> <p>No item found</p> </xsl:otherwise> </xsl:choose> </xsl:template>
Get random node by nodeTypeAlias
Hi, my tree look like this :
folder 1
- subfolder 1
--- file 1
--- file 2
- subfolder 2
--- file 3
--- file 4
And I like to get a random file, not the folder or subfolder. So I created a doctype 'multimedia_file'. Here's the xslt that does not work. I got an error : "Expression must evaluate to a node-set."
Thank you for your help!
I use this:
I think it would go more like this?
<xsl:param name="parentNode" select="1167" /> <xsl:variable name="nodeChoisies" select="$parentNode/descendant::node[@nodeTypeAlias = 'multimedia_file']" />
<xsl:variable name="numberOfNodes" select="count($nodeChoisies)"/>
<xsl:variable name="randomPosition" select="floor(Exslt.ExsltMath:random() * $numberOfNodes) + 1"/>
<xsl:variable name="randomNode" select="$nodeChoisies [position() = $randomPosition]"/>
The missing @ in front of nodeTypeAlias is what is likely giving you the error.
Ok, the code Jeff gave me bring the same error, so I tried kipusoep code and it almost works like I want. I changed the last line to have only one result :
But, how can I test if my randomNode has nodeTypeAlias = 'multimedia_file' before displays it?
Here's how I do it, along with a check for giving an alternate message if there is nothing to display.
cheers,
doug.
Thank you Douglas, it works like a charm!
is working on a reply...