I want to display a random member on my homepage. The only way I can find to select a member is by the function umbraco.library:GetMember('1060'), but I don't want to always show member 1060
I can't solve your exact problem right now, but here's some code I use to select a random node of site content on a page - you can probably modify it quite easily to pick members rather than content nodes:
Here's an alternative suggestion that makes use of the SQL for XSLT package. Install the package, follow the instructions, then try the following SQL query:
SELECT
TOP 1
CAST(xml AS XML)
FROM
cmsContentXml AS x
INNER JOIN cmsMember AS m ON x.nodeID = m.nodeID
ORDER BY
NEWID()
FOR XML
PATH('')
;
This will return a single XML node of the member data - selected randomly, (of course).
An example XSLT would be:
<xsl:template match="/">
<xsl:variable name="sql">
<xsl:text disable-output-escaping="yes"><![CDATA[
SELECT
TOP 1
CAST(xml AS XML)
FROM
cmsContentXml AS x
INNER JOIN cmsMember AS m ON x.nodeID = m.nodeID
ORDER BY
NEWID()
FOR XML
PATH('')
;
]]></xsl:text>
</xsl:variable>
<xsl:variable name="randomMember" select="jesper.sql:SQLXml($sql)"/>
<xsl:if test="count($randomMember/node) > 0">
<xsl:value-of select="$randomMember/node/@nodeName" />
</xsl:if>
</xsl:template>
I haven't tested this myself, but it should work... might need some playing around with it!
Select a random member in XSLT
I want to display a random member on my homepage. The only way I can find to select a member is by the function umbraco.library:GetMember('1060'), but I don't want to always show member 1060
Is there a way to select a random member in XSLT?
Hi Jeffrey,
I can't solve your exact problem right now, but here's some code I use to select a random node of site content on a page - you can probably modify it quite easily to pick members rather than content nodes:
Hope it helps...
Maybe this Wiki-Entry http://our.umbraco.org/wiki/reference/code-snippets/getmembersbygroupname can be usefull in combination with the random code Dan provided?
/Jan
Hi Jeffrey,
Here's an alternative suggestion that makes use of the SQL for XSLT package. Install the package, follow the instructions, then try the following SQL query:
This will return a single XML node of the member data - selected randomly, (of course).
An example XSLT would be:
I haven't tested this myself, but it should work... might need some playing around with it!
Good luck, Lee.
Quick update, (because we can't edit posts).
Get rid of the "FOR XML PATH('')" bit ... the SQL for XSLT extension does that automatically for you.
It will return the XML in a root element called <x> ... so change the XSLT example to use "$randomMember/x/node".
Cheers, Lee.
Hi Lee,
it works great!Thanks!
is working on a reply...