Created
January 16, 2013 21:41
-
-
Save designermonkey/4551196 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<data> | |
<thumbs> | |
<item>120</item> | |
<item>240</item> | |
<item>360</item> | |
</thumbs> | |
</data> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:exsl="http://exslt.org/common" | |
xmlns:math="http://exslt.org/math" | |
extension-element-prefixes="exsl math"> | |
<xsl:output method="xml" indent="yes" /> | |
<xsl:variable name="widths"> | |
<item>120</item> | |
<item>240</item> | |
<item>360</item> | |
</xsl:variable> | |
<xsl:template match="/"> | |
<xsl:call-template name="find-random-node"/> | |
</xsl:template> | |
<xsl:template name="find-random-node"> | |
<xsl:variable name="nodes" select="exsl:node-set($widths)"/> | |
<xsl:variable name="node-count" select="count($nodes/item)"/> | |
<xsl:variable name="random-node" select="ceiling(math:random() * $node-count)"/> | |
<count><xsl:value-of select="$node-count"/></count> | |
<random><xsl:value-of select="$random-node"/></random> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment