FormatFileSize
Originally contributed by Matt Bramer (@IOnline247) and adapted by Marc D Anderson (@sympmarc).
This template will format a file size (or any other number for that matter) into the appropriate unit of measure (Bytes, KB, MB, GB, TB) based on its magnitude. The template uses traditional conversion factors (powers of 2) rather than the more recent standard (powers of 10). See http://en.wikipedia.org/wiki/Megabyte.
<xsl:call-template name="FormatFileSize"> <xsl:with-param name="FileSize" select="@File_x0020_Size" /> </xsl:call-template>
<xsl:template name="FormatFileSize">
<xsl:param name="FileSize" />
<xsl:choose>
<xsl:when test="$FileSize > 1099511627776">
<xsl:value-of select="concat(format-number($FileSize div 1099511627776, '###.#'), 'TB')"/>
</xsl:when>
<xsl:when test="$FileSize > 1073741824">
<xsl:value-of select="concat(format-number($FileSize div 1073741824, '###.#'), 'GB')"/>
</xsl:when>
<xsl:when test="$FileSize > 1048576">
<xsl:value-of select="concat(format-number($FileSize div 1048576, '###.#'), 'MB')"/>
</xsl:when>
<xsl:when test="$FileSize > 1024">
<xsl:value-of select="concat(format-number($FileSize div 1024, '###.#'), 'KB')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(format-number($FileSize, '###.#'), 'Bytes')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>