View Full Version : Is it possible...
07-12-2002, 06:29 AM
Hello, I have a question (fancy that). Anyways, I am working on a webpage that uses XML and XSL to show data, and one of my types of data is small pieces of code like C++ or Java or something like that. My question is, is there a way to pick out various words and change their color everytime that they are displayed? Basicly I want to do something similar to syntax highlighting with XSL. Is it possible to do something like that, or will I have to write out all the code for that manually?
Thanks a lot.
Err, not to my knowledge:
<xsl:value-of select="translate(., "for", "<span class='keywords-FOR'>for</span>")/>
Would only replace text, not actually insert nodes.
Perhaps someone else has an idea? :)
07-12-2002, 05:57 PM
I don't really need completely new nodes that can be parsed. Like if I had teh folloing code:
for(int i = 0; i < 100; i++)
could I translate it to something like this?
<span class="reserved">for</span>(<span class="reserved">int</span> i = 0; i < 100; i++)
cout<< <span class="string">"Number: "</span> <<i<< <span class="character">'\n'</span>;
I don't actually have to do anythin with those inside tags, i just want them highlighted in different colors. Is that possible?
The only way I can think of right now is what I said in the other post. Inserting <span> tags is inserting nodes into the document template. translate() only replaces strings, which will be interpretted in character data, not raw markup.
Maybe I wasn't so clear in my previous reply...
07-13-2002, 10:30 AM
Can you not define your pieces of text as entities and re-use them in that way?
07-14-2002, 11:59 PM
I don't know what you are talking about. Are you saying do something like this?
&for;(∫ i = 0; i < 100; i++)
Would that work, and then I coudl replace the &for; and stuff with the styles and stuff that I need applied to them?
I believe entities can only contain character data, which means inserting markup/nodes isn't possible through that means.
I might be wrong though, but I'd be extremely surprised if you could.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.