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 898833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:06:52+00:00 2026-05-15T15:06:52+00:00

I seem to be having an issue with Xalan’s translate method. I have the

  • 0

I seem to be having an issue with Xalan’s translate method.
I have the following code:

translate(translate(string(name),'<sup>',''),'</sup>','')

This is used to remove <sup> and </sup> from string(name). Unfortunately when I do that, it seems to remove s, u and p from the names as well.
So names like sony Braiva <sup>tm</sup> become ony bravia tm

Thanks for you help in advance 🙂

  • 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-05-15T15:06:53+00:00Added an answer on May 15, 2026 at 3:06 pm

    Because you said that the translate() function is successfully removing <sup> and </sup>, I am assuming that <sup> is not an element in the XML document, but is encoded as text.

    The translate() function is defined to substitute individual characters and generally isn’t suitable for string replacement when the string length is greater than 1.

    It is possible to write and use a general string replacement recursive template/function in XSLT.

    XSLT 2.0 programmers can use the standard XPath 2.0 function replace().

    In your particular case even this this may be sufficient:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text()">
      <xsl:variable name="vPart1" select=
       "substring-before(., '&lt;sup>')"/>
    
      <xsl:value-of select="$vPart1"/>
    
      <xsl:variable name="vPart2" select=
       "substring-before(substring-after(., '&lt;sup>'),
                         '&lt;/sup>'
                         )"/>
    
      <xsl:value-of select="$vPart2"/>
    
      <xsl:variable name="vPart3" select=
       "substring-after(., '&lt;/sup>')"/>
    
      <xsl:value-of select="$vPart3"/>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on the following XML document:

    <name>
     <![CDATA[sony Braiva <sup>tm</sup> xxx]]>
    </name>
    

    the wanted result is produced:

    <name>
    sony Braiva tm xxx
    </name>
    

    Alternatively, here is the full-blown recursive template solution:

    <xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text()">
      <xsl:variable name="vFirstReplacement">
          <xsl:call-template name="replace">
           <xsl:with-param name="pText" select="."/>
           <xsl:with-param name="pPattern"
             select="'&lt;sup>'"/>
           <xsl:with-param name="pReplacement" select="''"/>
          </xsl:call-template>
      </xsl:variable>
    
      <xsl:call-template name="replace">
       <xsl:with-param name="pText"
            select="$vFirstReplacement"/>
       <xsl:with-param name="pPattern"
         select="'&lt;/sup>'"/>
       <xsl:with-param name="pReplacement" select="''"/>
      </xsl:call-template>
     </xsl:template>
    
     <xsl:template name="replace">
      <xsl:param name="pText"/>
      <xsl:param name="pPattern"/>
      <xsl:param name="pReplacement"/>
    
      <xsl:choose>
       <xsl:when test="not(contains($pText, $pPattern))">
        <xsl:value-of select="$pText"/>
       </xsl:when>
       <xsl:otherwise>
         <xsl:value-of select=
          "substring-before($pText, $pPattern)"/>
    
         <xsl:value-of select="$pReplacement"/>
    
         <xsl:call-template name="replace">
          <xsl:with-param name="pText" select=
           "substring-after($pText, $pPattern)"/>
          <xsl:with-param name="pPattern"
               select="$pPattern"/>
          <xsl:with-param name="pReplacement"
               select="$pReplacement"/>
         </xsl:call-template>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>
    

    When this transformation is applied on this XML document:

    <name>
     <![CDATA[sony Braiva <sup>tm</sup> xxx]]>
    </name>
    

    the wanted, correct result is produced:

    <name>
     sony Braiva tm xxx
    </name>
    

    Finally, here is the XSLT 2.0 solution:

    <xsl:stylesheet version="2.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
     <xsl:output omit-xml-declaration="yes" indent="yes"/>
     <xsl:strip-space elements="*"/>
    
     <xsl:template match="node()|@*">
      <xsl:copy>
       <xsl:apply-templates select="node()|@*"/>
      </xsl:copy>
     </xsl:template>
    
     <xsl:template match="text()">
      <xsl:value-of select=
       "replace(
                replace(., '&lt;sup>', ''),
                '&lt;/sup>',
                ''
                )
       "/>
     </xsl:template>
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seem to be having an issue with std::auto_ptr and assignment, such that the object
i'm having an issue with creating a query in oracle which doesnt seem to
I'm having a problem with my Seam code and I can't seem to figure
I seem to be having an issue with the conditional compilation tags directly en
I seem to be having an issue with Jax-WS and Jax-b playing nicely together.
Hi I seem to be having an issue trying to align an H1 tag
Right I seem to be having a issue inserting a image into a database
I seem to be having an odd issue whereby every time I try to
I seem to be having a strange issue with a 2D game I'm working
I am having an issue with a simple form uploading script. On this upload

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.