XSLT Hash Generator
Description
Generates an alpha numeric hash of a specified length using xslt 1. 0 and exlt math library.
The first character of the hash is always a letter.
XSLT
View Raw
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:math="http://exslt.org/math" extension-element-prefixes="math"> <xsl:template name="makeHash"> <xsl:param name="length">8</xsl:param> <xsl:param name="count" select="$length"/> <xsl:param name="hash"/> <xsl:variable name="possibleFirst">xABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:variable> <xsl:variable name="possible">xABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789</xsl:variable> <xsl:variable name="possibleFirstLength" select="string-length($possibleFirst)"/> <xsl:variable name="possibleLength" select="string-length($possible)"/> <xsl:choose> <xsl:when test="$count = $length"> <xsl:variable name="position" select="floor(math:random()* $possibleFirstLength)" /> <xsl:call-template name="makeHash"> <xsl:with-param name="length" select="$length"/> <xsl:with-param name="count" select="$count - 1"/> <xsl:with-param name="hash"> <xsl:value-of select="$hash"/> <xsl:value-of select="substring($possibleFirst, $position, 1)"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:when test="$count > 0"> <xsl:variable name="position" select="floor(math:random()* $possibleLength)" /> <xsl:call-template name="makeHash"> <xsl:with-param name="length" select="$length"/> <xsl:with-param name="count" select="$count - 1"/> <xsl:with-param name="hash"> <xsl:value-of select="$hash"/> <xsl:value-of select="substring($possible, $position, 1)"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$hash"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>