0

I have to do the following task

  • Set the four most significant bits of the a word(2bytes) to 0100'B, so the high nibble is "4". I am doing this by

    <xsl:value-of select="concat('4',substring($word,2,3))"/>

  • Set the two most significant bits of a word (2 bytes)(which is in string) to 10b so the high nibble will be one of "8", "9", "A", or "B" in XSLT.

How do I do this in xslt 1.0?

NJMR
  • 1,886
  • 1
  • 27
  • 46
  • Please explain more clearly. When you say "word", how many bits is this, and how exactly is it represented? (And are you really forced to use XSLT 1.0, which really wasn't designed for such tasks: using later versions would make it much easier). – Michael Kay Feb 05 '20 at 10:31
  • Yes, I am forced to use xslt 1.0 – NJMR Feb 05 '20 at 10:40

1 Answers1

1

I presume this is a continuation of Generating UUID in XSLT 1.0.

The simplest solution is to generate a random character from the string "89AB" to begin with. That way you have nothing to convert.

If you do want to process an existing hexadecimal digit, you could use the translate() function to convert:

0 to 8
1 to 9
2 to A
3 to B
4 to 8
5 to 9
6 to A
7 to B
C to 8
D to 9
E to A
F to B

according to the following table:

HEX     BINARY
0       00 00
1       00 01
2       00 10
3       00 11

4       01 00
5       01 01
6       01 10
7       01 11

8       10 00
9       10 01
A       10 10
B       10 11

C       11 00
D       11 01
E       11 10
F       11 11
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51