Jump to content

Find Non-ASCII character and replace with background color


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 post
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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...