[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Just for fun : XSLT rotating banners

Subject: Just for fun : XSLT rotating banners
From: Eric van der Vlist <vdv@xxxxxxxxxxxx>
Date: Wed, 02 Feb 2000 18:50:21 +0100
rotating banners
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.