Search code examples
xslttype-conversionhexasciiibm-datapower

Decimal -> HexaDecimal -> Character Encoding in XSLT


(1) My requirement is to convert a DECIMAL INPUT to hexadecimal notation with fixed 8 digits

(2) Convert/Map HEXADECIMAL RESULT to character set by picking 2 HEXADECIMAL characters at a time and append the respective character codes. Please refer to below link for character encoding
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/character-set-0127
https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/character-set-128255

(3) The final character encoding is showcased as OUTPUT

(4) Can XSLT handle all the special encoding character sets?

DECIMAL INPUT

 <decimal> 
   <input>2<input>
   <input>100<input>
   <input>819<input>
   <input>60<input>
 </decimal>

HEXADECIMAL RESULT

 <input>
   <hex>00000002</hex>
   <hex>00000064</hex>
   <hex>00000333</hex>
   <hex>0000003C</hex>
 </input>

OUTPUT - CHARACTER ENCODING

 <output>
   <charset>    </charset>
   <charset>   d</charset>
   <charset>   3</charset>
   <charset>   <</charset>
 </output>

Solution

  • Some of these codes are outside the ASCII range, but if by ASCII you mean Unicode, you could try

    <xsl:value-of select="concat('&amp;#x', hex, ';')"
      disable-output-escaping="yes"/>