Skip to content

Instantly share code, notes, and snippets.

@ijy
Created September 18, 2013 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ijy/6614868 to your computer and use it in GitHub Desktop.
Save ijy/6614868 to your computer and use it in GitHub Desktop.
Generate a random background image with XSLT, CSS, and Symphony CMS.
<!-- Add the 'math' namespace to your XML stylesheet (so we can use 'math:random') -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math"
extension-element-prefixes="math">
<!-- Pick a random number between 1 - 10 and set as a variable -->
<xsl:variable name="random-bg">
<xsl:value-of select="(floor(math:random()*10) mod 10) + 1" />
</xsl:variable>
<!-- Call the variable as an 'attribute value template' -->
<body class="bg-image-{$random-bg}">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment