I have a few strings containing a variant of Hexadecimal strings (source is framemaker if one would care). Strings could therefore look like
this is some sentence with some hex code\x27 s , and we need that
fixed.
and will need to be changed to
this is some sentence with some hex code’s , and we need that fixed.
In reality there can be a few of these in a single string, so I’m looking on the best way to walk through the text, capture all hex codes (looking like \x## ) and replace all of these codes with the correct character. I have made a xml list / lookup table containing all the characters as follows :
<xsl:param name="reflist">
<Code Value="\x27">'</Code>
<Code Value="\x28">(</Code>
<Code Value="\x29">)</Code>
<Code Value="\x2a">*</Code>
<Code Value="\x2b">+</Code>
<!-- much more like these... -->
</xsl:param>
For now I used a simple replace argument but there are simply too many characters to make this workable.
What’s the best way to do this?
Use
analyze-stringas inI would also suggest to use a key e.g.
then the lookup can be improved to
I have found some time to morph the suggestions made into working code, with the input being
and the complete stylesheet being
Saxon 9.4 transforms the input as follows: