Subject: RE: [xsl] Binary to Hex conversion From: "Scott Trenda" <Scott.Trenda@xxxxxxxx> Date: Tue, 20 Nov 2007 16:17:27 -0600 |
Here's mine: <stylesheet xmlns = "http://www.w3.org/1999/XSL/Transform" xmlns:str = "http://exslt.org/strings" xmlns:math = "http://exslt.org/math" version="1.0" exclude-result-prefixes="str math"> <variable name="str:digits" select="'0123456789'" /> <variable name="str:alphabet" select="'abcdefghijklmnopqrstuvwxyz'"/> <variable name="str:ALPHABET" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <variable name="math:base-list" select="concat($str:digits, $str:alphabet, $str:ALPHABET)"/> <template name="math:base-convert"> <param name="from-base"/> <param name="to-base"/> <param name="value"/> <call-template name="math:decimal-to-base"> <with-param name="base" select="$to-base"/> <with-param name="value"> <call-template name="math:base-to-decimal"> <with-param name="base" select="$from-base"/> <with-param name="value"> <choose> <when test="$from-base > 36"> <value-of select="$value"/> </when> <otherwise> <value-of select="translate($value, $str:ALPHABET, $str:alphabet)"/> </otherwise> </choose> </with-param> </call-template> </with-param> </call-template> </template> <template name="math:base-to-decimal"> <param name="base"/> <param name="value"/> <variable name="base-recurse"> <choose> <when test="string($value)"> <call-template name="math:base-to-decimal"> <with-param name="base" select="$base"/> <with-param name="value" select="substring($value, 1, string-length($value) - 1)"/> </call-template> </when> <otherwise>0</otherwise> </choose> </variable> <value-of select="string-length(substring-before($math:base-list, substring($value, string-length($value)))) + $base * $base-recurse"/> </template> <template name="math:decimal-to-base"> <param name="base"/> <param name="value" select="0"/> <if test="number($value)"> <call-template name="math:decimal-to-base"> <with-param name="base" select="$base"/> <with-param name="value" select="floor($value div $base)"/> </call-template> <value-of select="substring($math:base-list, ($value mod $base) + 1, 1)"/> </if> </template> </stylesheet> ~ Scott -----Original Message----- From: Jeff Hooker [mailto:jeff@xxxxxxxxxxxx] Sent: Tuesday, November 20, 2007 4:13 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Binary to Hex conversion I'm sure I've seen this discussed somewhere, but the archive appears dry. I have a binary value that is a result of concatenating the default values for a series of bits, and now I need to convert the complete value to hex so that I can display it as the "reset value" for the whole register. eg. <bit> <bit_default>0</bit_default> </bit> <bit> <bit_default>1</bit_default> </bit> <bit> <bit_default>X</bit_default> <!--null bit--> </bit> <bit> <bit_default>1</bit_default> </bit> I gather them into a variable, substitute the Xs for 0s to allow for conversion to hex, and then..stop. I've searched for any math extensions that would allow an easy conversion to hex, but have come up dry, and I'm simply not up to the task of creating a recursive template to perform the conversion; on an 8000 page document it would likely still be running over the Christmas break. A register can be hundreds of bits in length, hence my desire to present the default settings in a more compressed format than their binary values. Any suggestions? Thanks, Jeff.
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Binary to Hex conversion, Jeff Hooker | Thread | [xsl] question about a past problem, Andreas Peter |
[xsl] Binary to Hex conversion, Jeff Hooker | Date | Re: [xsl] Special footer on fifth p, G. Ken Holman |
Month |