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 🙂
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:
When this transformation is applied on the following XML document:
the wanted result is produced:
Alternatively, here is the full-blown recursive template solution:
When this transformation is applied on this XML document:
the wanted, correct result is produced:
Finally, here is the XSLT 2.0 solution: