Subject: Just for fun : XSLT rotating banners From: Eric van der Vlist <vdv@xxxxxxxxxxxx> Date: Wed, 02 Feb 2000 18:50:21 +0100 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: Multiple if, Kay Michael | Thread | XSLT processing corrupts character , Christian Mallwitz |
RE: multiple input files to one out, sara . mitchell | Date | Re: recursively including xml-files, Steve Tinney |
Month |