This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Just for fun : XSLT rotating banners
- To: xsl-list at mulberrytech dot com
- Subject: Just for fun : XSLT rotating banners
- From: Eric van der Vlist <vdv at dyomedea dot com>
- Date: Wed, 02 Feb 2000 18:50:21 +0100
- Organization: Dyomedea
- Reply-To: xsl-list at mulberrytech dot com
Hi,
I needed a rotating banners mechanism for prototyping a XML/XSLT based
site and I have been (again ;) amazed by the flexibility provided by XML
and XSLT (and xt's java extension since XPATH is missing a random
function)...
------------------- xml -----------------
<banners>
<banner>
<a href="/foo.xml" >
<img src="/images/foo.png" border="0" alt="alt text"/>
</a>
</banner>
<banner>
<a href="/bar.xml">
<img src="/images/bar.png" border="0" alt="alt text"/>
</a>
</banner>
</banners>
------------------- xsl -----------------
../..
xmlns:math="http://www.jclark.com/xt/java/java.lang.Math"
../..
<xsl:template match="document-banner">
<xsl:param name="cnt" select="count(/banners/banner)"/>
<xsl:param name="rnd" select="math:random()"/>
<xsl:param name="idx" select="round(($cnt -1) * $rnd) +1"/>
<xsl:apply-templates select="/banners/banner[position()=$idx]/*"/>
</xsl:template>
------------------------------------------
I will probably not keep it for the production release (it would
probably scale very badly if you add more banners and, since my XML
Server dream is not yet implemented ;) I can't easily update a counter),
but it's allowing to rotate not only pictures but any XML snippet which
I find very flexible and convenient.
I hope you'll appreciate these lines as much as I have !
Eric
--
------------------------------------------------------------------------
Eric van der Vlist Dyomedea
http://www.dyomedea.com http://www.ducotede.com
------------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list