Topic
8 replies Latest Post - ‏2012-12-27T09:12:35Z by Daviiid
Daviiid
Daviiid
215 Posts
ACCEPTED ANSWER

Pinned topic convert hex to iso-8859-1

‏2012-12-17T17:41:09Z |
Hello

I have this hexadecimal string C389

I need to transfrom this hex string to a text encoded in iso-8859-1. The result I expect is here É

Is there a way to transfrom an utf8 hex string in a iso-8859-1 string?
Updated on 2012-12-27T09:12:35Z at 2012-12-27T09:12:35Z by Daviiid
  • HermannSW
    HermannSW
    2826 Posts
    ACCEPTED ANSWER

    Re: convert hex to iso-8859-1

    ‏2012-12-17T19:14:53Z  in response to Daviiid
    Hi David,

    dp5-l3:2223 is a coproc2 endpoint with minimal output escaping selected:
    $ echo "<x>C389</x>" | coproc2 u8hx2iso1.xsl - http://dp5-l3:2223 -s | od -tcx10000000 311
             c9
    0000001
    $ 
    $ cat u8hx2iso1.xsl 
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:dp="http://www.datapower.com/extensions"
      extension-element-prefixes="dp"
    >
      <xsl:output method="xml" encoding="iso-8859-1"/>
     
      <xsl:template match="/">
        <xsl:variable name="b64"
           select="substring(dp:radix-convert(concat('ffffff', .),16,64), 5)"/>
     
        <xsl:copy-of select="dp:decode($b64, 'base-64')"/>
      </xsl:template>
    </xsl:stylesheet>
    $
    


     
    Hermann <myXsltBlog/> <myXsltTweets/>
    Updated on 2014-03-25T02:44:36Z at 2014-03-25T02:44:36Z by iron-man
    • HermannSW
      HermannSW
      2826 Posts
      ACCEPTED ANSWER

      Re: convert hex to iso-8859-1

      ‏2012-12-17T19:16:53Z  in response to HermannSW
      1st display line corrected -- btw, dp:decode() does utf-8 validation for you.
      $ echo "<x>C389</x>" | coproc2 u8hx2iso1.xsl - http://dp5-l3:2223 -s | od -tcx1
      0000000 311
               c9
      0000001
      $
      
      Updated on 2014-03-25T02:44:32Z at 2014-03-25T02:44:32Z by iron-man
    • Daviiid
      Daviiid
      215 Posts
      ACCEPTED ANSWER

      Re: convert hex to iso-8859-1

      ‏2012-12-17T19:46:25Z  in response to HermannSW
      Thanks Hermann ,
      Does it works if i do this transformation and do a dp:url-open with this first transformation in the same StyleSheet?
      I read a post of you and you explained that we have to call a XML FireWall service (loopback with non xml input) for transform the input message from utf-8 to iso-8859
    • Daviiid
      Daviiid
      215 Posts
      ACCEPTED ANSWER

      Re: convert hex to iso-8859-1

      ‏2012-12-21T15:19:08Z  in response to HermannSW
      Hello Hermann

      Juste a question : why do i need to concat my value with 'ffffff' and next substring-after fifth position?

      Another question : i attach a file which contains value i retrieve from a database

      I do your transformation :
      
      substring(dp:radix-convert(concat(
      'ffffff',dp:radix-convert(dp:encode(normalize-space($resultDataBase),
      'base-64'),64,16)),16,64),5)
      


      The result of this transformation is :
      
      bml0ZU1pbmlHYXI+PC9MX0VkaXRpb25Vbml0ZU1pbmlHYXI+PE10R2FyYW50aUdhcmFudGllPjQ1ODAwMDwvTXRHYXJhbnRpR2FyYW50aWU+PENfVW5pdGVNdEdhcmFudGk+NTwvQ19Vbml0ZU10R2FyYW50aT48TF9Vbml0ZU10R2FyYW50aT5ldXJvcyBwYXIgc2luaXN0cmU8L0xfVW5pdGVNdEdhcmFudGk+PFRhdXhDb3Rpc0Jhc2VHYXI+LjAwMDA8L1RhdXhDb3Rpc0Jhc2VHYXI+PENfVW5pdGVUYXV4Q290aXM+PC9DX1VuaXRlVGF1eENvdGlzPjxMX1VuaXRlVGF1eENvdGlzYXRpb24+PC9MX1VuaXRlVGF1eENvdGlzYXRpb24+PE1pbmlFeHByaW1lRW5OYlN0YXQ+LjAwMDA8L01pbmlFeHByaW1lRW5OYlN0YXQ+PE10TWluaUNvdGlzYXRpb25IVD4uMDA8L010TWluaUNvdGlzYXRpb25IVD48TW9udGFudEh0Rm9yZmFpdD4yMTUuNzY8L01vbnRhbnRIdEZvcmZhaXQ+PE5fR3JvdXBlbWVudD4wPC9OX0dyb3VwZW1lbnQ+PEFubmVlRGVidXRWYWxpZGl0ZT4yMD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0NyaXRlcmU+PFZhbGV1ckNyaXRlcmU+PC9WYWxldXJDcml0ZXJlPjxMX0NvbnZlbnRpb24+PC9MX0NvbnZlbnRpb24+PENfQ29udHJhdFR5cGU+RzAzPC9DX0NvbnRyYXRUeXBlPjxMX0NvbnRyYXRUeXBlPlBST1RFQ1RJT04gUFJPRkVTU0lPTk5FTExFIERFUyBBUlRJU0FOUyBEVSBCQVRJTUVOVCAtIEFDVElWSVRFPC9MX0NvbnRyYXRUeXBlPjxDX05hdHVyZU9iamV0PkFDPC9DX05hdHVyZU9iamV0PjxMX05hdHVyZU9iamV0Pk9iamV0IEFjdGl2aXTDqXM8L0xfTmF0
      


      It's strange because the result of transformation is truncated..

      Attachments

      • Liv2luv
        Liv2luv
        573 Posts
        ACCEPTED ANSWER

        Re: convert hex to iso-8859-1

        ‏2012-12-21T16:55:40Z  in response to Daviiid
        >Juste a question : why do i need to concat my value with 'ffffff' and next substring-after fifth position?

        To preserve the leading spaces.

        >Another question : i attach a file which contains value i retrieve from a database

        I would do dp:dump-nodes or save the result of transformation into a context variable to see what it looks like in DP; could be a imitation with size in database ?
  • HermannSW
    HermannSW
    2826 Posts
    ACCEPTED ANSWER

    Re: convert hex to iso-8859-1

    ‏2012-12-21T19:19:45Z  in response to Daviiid
    "dp:radix-convert()" is a "number" function, and therefore leading 0x00 bytes would be removed.
    The prepended "ffffff" (can be any 3 byte value not starting with 00) gets converted to base64 string of length 4
    which can easily be stripped by "substring(_,5)" afterwards.

    Is $resultDataBase serialized XML?
    Can you attach here, and tell your firmware version?

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    • Daviiid
      Daviiid
      215 Posts
      ACCEPTED ANSWER

      Re: convert hex to iso-8859-1

      ‏2012-12-27T09:12:35Z  in response to HermannSW
      thanks Hermann

      I found a solution. I do not use a transformation like this

      
      <xsl:variable name=
      "result" select=
      "dp:sql-execute('LOGIBAT',$requete)"/> <xsl:variable name=
      "dummy"> <dp:url-open target=
      "{$target}" response=
      "responsecode-ignore"> <xmlBase64> <xsl:for-each select=
      "$result//row"> <xsl:value-of disable-output-escaping=
      "no" select=
      "substring(dp:radix-convert(concat('ffffff',dp:radix-convert(dp:encode(normalize-space(column[name = 'X06LIB']/value/text()),'base-64'),64,16)),16,64),5)"/> </xsl:for-each> </xmlBase64> </dp:url-open> </xsl:variable>
      


      but i use this

      
      <xsl:variable name=
      "result" select=
      "dp:sql-execute('LOGIBAT',$requete)"/> <xsl:variable name=
      "dummy"> <dp:url-open target=
      "{$target}" response=
      "responsecode-ignore"> <xsl:for-each select=
      "$result//row"> <xsl:value-of disable-output-escaping=
      "no" select=
      "normalize-space(column[name = 'X06LIB']/value/text())"/> </xsl:for-each> </dp:url-open> </xsl:variable>
      


      I attach $result