|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Just for fun : XSLT 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








