IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
2 replies Latest Post - ‏2012-03-20T20:03:38Z by Ivan261
4 Posts

Pinned topic Converting binaryNode to xs:string

‏2012-03-19T15:03:04Z |
My task is converting binary data into a string. Encoding of the binary data is known, but may not be UTF-8.
My solution:

<func:function name=
"nf:binToStr"> <xsl:param name=
"data"/> <xsl:param name=
"encoding" select=
"UTF-8"/> <xsl:choose> <xsl:when test=
"$encoding = 'UTF-8'"> <func:result select=
"dp:decode(dp:binary-encode($data), 'base-64')"/> </xsl:when> <xsl:otherwise> <xsl:variable name=
"v_dataHex" select=
"dp:radix-convert(dp:binary-encode($data), 64, 16)"/> <xsl:variable name=
"v_encodingHex" select=
"dp:radix-convert(dp:encode($encoding, 'base-64'), 64, 16)"/> <!-- <?xml version=
"1.0" encoding=
" + "?><t><![CDATA[ + ]]><\t> --> <xsl:variable name=
"v_base64Xml" select=
'3C3F786D6C2076657273696F6E3D22312E302220656E636F64696E673D22', $v_encodingHex, 
'223F3E3C743E3C215B43444154415B', $v_dataHex, 
'5D5D3E3C2F743E'), 16, 64)
"/> <xsl:variable name=
"v_dataXml" select=
"dp:parse($v_base64Xml, 'base-64')"/> <xsl:variable name=
"v_res" select=
"$v_dataXml/t/text()"/> <func:result select=
"$v_res"/> </xsl:otherwise> </xsl:choose> </func:function>

But may be there are a more elegant solutions without creating of the xml and dp:parse.
Updated on 2012-03-20T20:03:38Z at 2012-03-20T20:03:38Z by Ivan261
  • HermannSW
    4491 Posts

    Re: Converting binaryNode to xs:string

    ‏2012-03-19T22:29:44Z  in response to Ivan261

    first, a very creative solution.
    And secure wrt how you deal with non-XML data (binaryNode) and which conversion functions you use.

    But for me it is not possible to pass a binaryNode as argument to a func:function call,
    see attached stylesheet. I verified that your method works by eliminating the function call.

    If you want to go that route, you should consider to pass the base64 encoded binaryNode as argument to your function.

    See slides 6-8 from this webcast for details on another method:



    • Ivan261
      4 Posts

      Re: Converting binaryNode to xs:string

      ‏2012-03-20T20:03:38Z  in response to HermannSW
      Thank you Hermann.
      I would like to parse text/plain get response. I do not know the encoding before receiving header Content-Type. I parse the header of the means regexp:match and recognize the encoding.
      In our appliance XI50 4.0.1 func:function call work with binaryNode as argument. Maybe it is 4.0.x firmware feature.