The Quotes and Quote have each a document type "Quotes" and "Quote", where Quote has the properties quoteText and quoteName.
How can I create my xslt so for each Quote node, which use the Quote document type, it writes the quote text and quote name.. and then display a random node, so I can place the macro on eg. frontpage and a subpage?
and added a parameter with alias randomNode to the macro, but it doesn't seem to give a output. I'm using Umbraco 4.7 with the new xml schema .. I have tried with /macro/randomNode/* [@isDoc] too, but doesn't work .
So if you take a look at the temporary url here: http://d22299829.u330.surftown.dk/da/ydelser.aspx , then the quote in the left sidebar on subpages change when you refresh the page or go to another page..
How to display random quote?
Hi
I have the following structure of my content:
- Content
The News and Quotes node are at same level.
Hi, for the random node, it's simple :
For the macro, you name the parameter alias randomNode and choose contentRandom as type.
Hi Bjarne
I haven't tested it, but it should work
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umb="urn:umbraco.library" xmlns:emath="urn:Exslt.ExsltMath" exclude-result-prefixes="msxml umb emath "> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="currentPage"/> <xsl:variable name="random" select="floor(emath:random() * count($currentPage/ancestor-or-self::Master/descendant-or-self::Quote)) + 1"/> <xsl:template match="/"> <xsl:apply-templates select="$currentPage/ancestor-or-self::Master/descendant-or-self::Quote[$random]" /> </xsl:template> <xsl:template match="Quote"> <div id="randquote"> <xsl:apply-templates select="quoteName[normalize-space()]" /> <xsl:apply-templates select="quoteText[normalize-space()]" /> </div> </xsl:template> <xsl:template match="quoteName"> <h1> <xsl:value-of select="." /> </h1> </xsl:template> <xsl:template match="quoteText"> <p> <xsl:value-of select="." /> </p> </xsl:template> </xsl:stylesheet>I have wrote the following in my XSLT:
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:variable name="randomNode" select="/macro/randomNode/*"/>
<xsl:value-of select="$randomNode/quoteName" disable-output-escaping="yes" />
<p><xsl:value-of select="$randomNode/quote" disable-output-escaping="yes" />
</p>
</xsl:template>
and added a parameter with alias randomNode to the macro, but it doesn't seem to give a output. I'm using Umbraco 4.7 with the new xml schema .. I have tried with /macro/randomNode/* [@isDoc] too, but doesn't work .
Is something missing?
Hi Sebastian
Thank you so much for your input :)
Just what I needed... it now works perfectly as intended.
Your code works, just my Master doc types actually is called MainMaster.
So if you take a look at the temporary url here: http://d22299829.u330.surftown.dk/da/ydelser.aspx , then the quote in the left sidebar on subpages change when you refresh the page or go to another page..
Once again I appreciate your help..
- Bjarne
Hi Sebastian
Would you mind sharing this in the wiki if it does not already exist in there? Nice solution indeed :-)
/Jan
@Jan and @Bjarne
Here you go: http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/xslt-getting-a-random-document-when-the-page-reloads
I've optimized it a bit using root instead of the MainMaster doctype.
is working on a reply...
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.