Jump to content

Find Non-ASCII character and replace with background color


Raja1205

Recommended Posts

Hello Friends, I am new to XSLT. So please advise anyone. My requirement is as follows: I want to find out an Non-ASCII characters (especially Superscript and Subscript symbols) and replace with background color. Is it possible to handle this in XSL/XSLT? Snippet of the XML Code:--------------------------------<p>For the first three decades of the history<sup>3</sup> ...</p><p>However, the shock of deadly confrontations with superior Japanese fighters ...</p> Thanks for your suggestion and help in advance. Regards,Raja. S

Link to comment
Share on other sites

Which version of XSLT do you use or want to use? XSLT 2.0 has better string processing and replacement than XSLT 1.0.And what exactly does "replace with background color" mean? If the input XML (or HTML?) is

<p>For the first three decades[color=#ff0000]⁴[/color] of the history<sup>3</sup> ...</p>

, how should the result look you want to create with XSLT?

Link to comment
Share on other sites

Thanks for the reply. I use XSLT 1.0 and i want to do transformation from XML to HTML (i.e Required output is .html).In the output HTML, Back ground color need to be added for the superscript/subscript symbol (i.e ⁴ or ₅) Example: the symbol ⁴ requires background color yellow in the HTML output. Note: superscript/subscript symbols shoud not be converted to either HTML/UNICODE entity and that should be retained as symbol with background color. Thanks,Raja. S

Edited by Raja1205
Link to comment
Share on other sites

XSLT 1.0 is not good at such tasks, consider to use XSLT 2.0 and xsl:analyze-string. If you really want to use it with XSLT 1.0 then you I put together http://home.arcor.de/martin.honnen/xslt/test2012062803.xml, works for me with Firefox and Opera, with IE 9 I get unwanted white space inserted, I don't have time to debug that. Stylesheet is at http://home.arcor.de/martin.honnen/xslt/test2012062803.xsl, uses a file mapping characters to colors at http://home.arcor.de/martin.honnen/xslt/test2012062804.xml. And the solution is rather inefficient as it processes the contents of each text node character by character. And recursive template might run out of stack space if the XSLT processor does not implement tail recursion.

Link to comment
Share on other sites

Hi Martin Honnen, Thank you so much, It woks well. Is it possible to set the background color instead of foreground color (text color) for the superscript/subscript symbols? I am new to this forum and I don't know how to close the responded topic. Could you advise me? Thanks,Raja. S

Edited by Raja1205
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...