Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] decoding hex string to ascii or UTF-8

From: Steven Hentschel <steven.hentschel@----------->
To:
Date: 7/2/2008 8:36:00 AM
Many thanks, I wasn't aware of the codepoints-to-string() function which does
exactly what I was after.

My original example was corrupted because I'm sending via hotmail and forgot
to escape the angle brackets!! As you say, mechanically calculating the
hexadecimal code
point and translating it is labourious but straightforward.

<!--function  hex:hex2string() recursively translates hex into ascii, uses
hex:hex2char to translate individual bytes-->
<xsl:function name="hex:hex2string" as="xs:string">
<xsl:param name="hexstring" as="xs:string"/>
<xsl:choose>
  <xsl:when test="string-length($hexstring) gt 2">
    <xsl:value-of select="concat(hex:hex2char(substring($hexstring, 1, 2)),
hex:hex2string(substring($hexstring, 3)))"/>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="hex:hex2char(substring($hexstring, 1, 2))"/>
  </xsl:otherwise>
</xsl:choose>
</xsl:function>

<!--function  hex:hex2char() translates a byte as hex into an ascii char-->
<xsl:function name="hex:hex2char" as="xs:string">
<xsl:param name="hexchar" as="xs:string"/>
<xsl:value-of>
      <xsl:choose>
        <xsl:when test="substring($hexchar, 1, 2) = '20'"><xsl:text>
</xsl:text></xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '21'">!</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '22'">"</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '23'">#</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '24'">$</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '25'">%</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '26'">&</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '27'">&apos;</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '28'">(</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '29'">)</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2A'">*</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2B'">+</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2C'">,</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2D'">-</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2E'">.</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '2F'">/</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '30'">0</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '31'">1</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '32'">2</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '33'">3</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '34'">4</xsl:when>
        <xsl:when test="substring($hexchar, 1, 2) = '35'">5</xsl:when>

etc

Steven Hentschel
_________________________________________________________________

http://clk.atdmt.com/UKM/go/msnnkmgl0010000002ukm/direct/01/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent