Converting decimal to hexadecimal
Description
Converting decimal to hexadecimal. An example of a template:
<xsl:call-template name="ConvertDecToHex">
<xsl:with-param name="index">15</xsl:with-param>
</xsl:call-template>
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template name="ConvertDecToHex"> <xsl:param name="index" /> <xsl:if test="$index > 0"> <xsl:call-template name="ConvertDecToHex"> <xsl:with-param name="index" select="floor($index div 16)" /> </xsl:call-template> <xsl:choose> <xsl:when test="$index mod 16 < 10"> <xsl:value-of select="$index mod 16" /> </xsl:when> <xsl:otherwise> <xsl:choose> <xsl:when test="$index mod 16 = 10">A</xsl:when> <xsl:when test="$index mod 16 = 11">B</xsl:when> <xsl:when test="$index mod 16 = 12">C</xsl:when> <xsl:when test="$index mod 16 = 13">D</xsl:when> <xsl:when test="$index mod 16 = 14">E</xsl:when> <xsl:when test="$index mod 16 = 15">F</xsl:when> <xsl:otherwise>A</xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> </xsl:if> </xsl:template> </xsl:stylesheet>