How to convert a negative decimal into hexadecimal using xslt 1

ぐ巨炮叔叔 提交于 2019-12-02 09:38:54

To convert a decimal number to 32-bit signed hexadecimal in pure XSLT 1.0:

<xsl:template name="dec2signedhex">
    <xsl:param name="decimal"/>
    <xsl:variable name="n">
        <xsl:choose>
            <xsl:when test="$decimal &lt; 0">
                <xsl:value-of select="$decimal + 4294967296"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$decimal"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:variable name="q" select="floor($n div 16)"/>
    <xsl:if test="$q">
        <xsl:call-template name="dec2signedhex">
            <xsl:with-param name="decimal" select="$q"/>
        </xsl:call-template>
    </xsl:if>
    <xsl:value-of select="substring('0123456789ABCDEF', $n mod 16 + 1, 1)"/>
</xsl:template>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!