Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8827101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:18:03+00:00 2026-06-14T07:18:03+00:00

I have a few strings containing a variant of Hexadecimal strings (source is framemaker

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:18:04+00:00Added an answer on June 14, 2026 at 7:18 am

    Use analyze-string as in

    <xsl:template match="text()">
      <xsl:analyze-string select="." regex="\\x[0-9a-f]{{2}}" flags="i">
        <xsl:matching-substring>
          <xsl:value-of select="$reflist/Code[@Value = .]"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </xsl:template>
    

    I would also suggest to use a key e.g.

    <xsl:param name="reflist" as="document-node()">
      <xsl:document>
        <Root>
          <Code Value="\x27">'</Code>
          <Code Value="\x28">(</Code>
          <Code Value="\x29">)</Code>
          <Code Value="\x2a">*</Code>
          <Code Value="\x2b">+</Code>
          <!-- much more like these... -->
        </Root>
      </xsl:document>
    </xsl:param>
    
    <xsl:key name="code-by-value" match="Code" use="@Value"/>
    

    then the lookup can be improved to

    <xsl:template match="text/text()">
      <xsl:analyze-string select="." regex="\\x[0-9a-f]{{2}}" flags="i">
        <xsl:matching-substring>
          <xsl:value-of select="key('code-by-value', ., $reflist)"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </xsl:template>
    

    I have found some time to morph the suggestions made into working code, with the input being

    <root>
      <text>this is some sentence with some hex code\x27 s , and we need that \x28and this\x29 fixed.</text>
    </root>
    

    and the complete stylesheet being

    <xsl:stylesheet 
      version="2.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs">
    
    <xsl:param name="reflist" as="document-node()">
      <xsl:document>
        <Root>
          <Code Value="\x27">'</Code>
          <Code Value="\x28">(</Code>
          <Code Value="\x29">)</Code>
          <Code Value="\x2a">*</Code>
          <Code Value="\x2b">+</Code>
          <!-- much more like these... -->
        </Root>
      </xsl:document>
    </xsl:param>
    
    <xsl:key name="code-by-value" match="Code" use="@Value"/>
    
    <xsl:template match="@* | node()">
      <xsl:copy>
        <xsl:apply-templates select="@* , node()"/>
      </xsl:copy>
    </xsl:template>
    
    <xsl:template match="text/text()">
      <xsl:analyze-string select="." regex="\\x[0-9a-f]{{2}}" flags="i">
        <xsl:matching-substring>
          <xsl:value-of select="key('code-by-value', ., $reflist)"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
          <xsl:value-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
    </xsl:template>
    
    </xsl:stylesheet>
    

    Saxon 9.4 transforms the input as follows:

    <root>
      <text>this is some sentence with some hex code' s , and we need that (and this) fixed.</text>
    </root>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few strings(about 100) and I want to store them in a
I'm just starting with programming. I have a list of a few strings and
I have a few unit tests that require very large strings for the test
Say I have a few string like Hi my name is <Name> Hi <name>,
I have a few HTML files that I'd like to include via tags in
I have an arrays.xml file containing quite a few string-array elements for use with
I have a few very large files each of 500MB++ size, containing integer values
I have an AJAX-request that returns a json object containing a few values with
I'm using Swing and I have a JFrame containing a few JPanels, and inside
I have a text file containing 7000 lines of strings. I got to search

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.