Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-12-2002, 06:29 AM   PM User | #1
Evlich
New Coder

 
Join Date: Jun 2002
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Evlich is an unknown quantity at this point
Is it possible...

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.
~evlich
Evlich is offline   Reply With Quote
Old 07-12-2002, 07:12 AM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Err, not to my knowledge:

<xsl:template match="theNodeContainingC++Code">
<xsl:value-of select="translate(., "for", "<span class='keywords-FOR'>for</span>")/>
</xsl:template>

Would only replace text, not actually insert nodes.

Perhaps someone else has an idea?
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 07-12-2002, 05:57 PM   PM User | #3
Evlich
New Coder

 
Join Date: Jun 2002
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Evlich is an unknown quantity at this point
I don't really need completely new nodes that can be parsed. Like if I had teh folloing code:
<code lang="cpp16">
for(int i = 0; i < 100; i++)
{
cout<<"Number: "<<i<<'\n';
}
</code>
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?
~evlich
Evlich is offline   Reply With Quote
Old 07-12-2002, 11:35 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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...
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 07-13-2002, 10:30 AM   PM User | #5
mpjbrennan
Regular Coder

 
Join Date: Jun 2002
Location: Newcastle, England
Posts: 178
Thanks: 0
Thanked 0 Times in 0 Posts
mpjbrennan is an unknown quantity at this point
Can you not define your pieces of text as entities and re-use them in that way?

patrick
mpjbrennan is offline   Reply With Quote
Old 07-14-2002, 11:59 PM   PM User | #6
Evlich
New Coder

 
Join Date: Jun 2002
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts
Evlich is an unknown quantity at this point
I don't know what you are talking about. Are you saying do something like this?
&for;(&int; i = 0; i < 100; i++)
{
cout<<&str;"hello "&str;<<i<<&char;'\n'&char;;
}
Would that work, and then I coudl replace the &for; and stuff with the styles and stuff that I need applied to them?
~evlich
Evlich is offline   Reply With Quote
Old 07-15-2002, 02:15 AM   PM User | #7
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
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.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:24 PM.


Advertisement
Log in to turn off these ads.