Subject: Re: [xsl] decoding hex string to ascii or UTF-8 From: Steven Hentschel <steven.hentschel@xxxxxxxxxxx> Date: Wed, 2 Jul 2008 09:35:34 +0100 |
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'">'</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/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] decoding hex string to as, Dimitre Novatchev | Thread | Re: [xsl] applying templates to att, Wendell Piez |
Re: [xsl] applying templates to att, Liam Quin | Date | [xsl] group by tags, IZASKUN GUTIERREZ GU |
Month |